简体   繁体   English

Spring Boot默认表单绑定

[英]Spring boot default form binding

I have a spring boot project. 我有一个春季启动项目。 I have a form where I bind an entity property using its id(Long). 我有一个表单,在其中使用实体的id(Long)绑定实体属性。 Like so, 像这样

<input name="entityProperty" value="1" ... />

It binds successfully when submitted (there's already an existing entity with id=1). 提交时成功绑定(已经有一个id = 1的现有实体)。

However, I export this project via jar file and use it in another Spring MVC project (not Spring boot). 但是,我通过jar文件导出了这个项目,并在另一个Spring MVC项目(不是Spring boot)中使用了它。 Now, I'm getting an error when binding this same scenario: backingObject.entityProperty is null . 现在,在绑定相同场景时出现错误: backingObject.entityPropertynull

It's similar to this question . 这类似于这个问题 It's suggested there that I have to create a conversion service, from Long to Type of my entity. 建议在那里创建一个转换服务,从我的实体的Long到Type。

Do I have to do that solution also? 我也必须这样做吗? Why didn't I have to provide that in my spring boot project? 为什么我不必在Spring Boot项目中提供它? What's the default configuration for spring boot? Spring Boot的默认配置是什么?

I fix this by adding a custom property editor, 我通过添加自定义属性编辑器来解决此问题,

public class BaseEntityEditor extends PropertyEditorSupport {}

However, it is still unclear to me why it works by default in my Spring Boot application. 但是,我仍然不清楚为什么它默认在我的Spring Boot应用程序中起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM