表单值为空而不是“"在春天 [英] Form Values to be Null instead of "" in Spring
问题描述
我正在使用 Spring MVC
。我使用表单提交。当我不给任何值的形式意味着它带有空字符串。是否可以设置空值而不是(空)
预先感谢您的帮助。可能这是一个愚蠢的问题。
您必须使用@InitBinder,因为在春天它总是返回空白值的形式。你必须在你的控制器中添加这个元素
$ p $ lt; code> @InitBinder / *提交表单时将空字符串转换为null * /
public void initBinder(WebDataBinder binder){
binder.registerCustomEditor(String.class,new StringTrimmerEditor(true));
}
请参阅 http://www.bitspedia.com/2012/09/spring-mvc-31- how-to-convert-form-empty.html
I am using Spring MVC
. I used the form Submit. When i does not give any values to the form means It comes with "" empty string. Is it possible to set null value instead of ""(empty)
Thanks in advance for your help. May be this is a silly question. I am new to this stuff.
You have to use the @InitBinder because in spring it always return "" for the blank values in form. You have to add this in your controller
@InitBinder /* Converts empty strings into null when a form is submitted */
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
}
Refer from the http://www.bitspedia.com/2012/09/spring-mvc-31-how-to-convert-form-empty.html
这篇关于表单值为空而不是“"在春天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!