Spring 如果绑定表单字段为空,则将其设置为NULL

Spring 如果绑定表单字段为空,则将其设置为NULL,spring,spring-mvc,Spring,Spring Mvc,在SpringMVC中,是否可以将绑定表单字段设置为NULL(而不是空字符串) 如果未输入任何内容,则“我的域对象”字段最终为空。在这种情况下,我需要将其设置为NULL <form:input path="myObject.department" /> 为字符串添加自定义编辑器,将空字符串转换为空字符串 @InitBinder public void initBinder(WebDataBinder binder) { binder.registerCustomEdit

在SpringMVC中,是否可以将绑定表单字段设置为NULL(而不是空字符串)

如果未输入任何内容,则“我的域对象”字段最终为空。在这种情况下,我需要将其设置为NULL

<form:input path="myObject.department" />

为字符串添加自定义编辑器,将空字符串转换为空字符串

@InitBinder
public void initBinder(WebDataBinder binder) {  
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));  
}

我找到了答案:谢谢你;虽然这是可行的,但我们有嵌套的子元素,只有“leaf”元素被设置为NULL。将创建父对象。在我们的例子中,如果所有子项都为NULL,那么父项也应该为NULL。