forms - 在 Spring MVC 中将值设置为 NULL 而不是空字符串

标签 forms spring web-applications spring-mvc

我正在使用 Spring MVC。我的页面上有一个表格。当我没有在表单中输入任何值并提交时,它带有空字符串 "".

是否可以设置 null 值而不是空字符串?

提前感谢您的帮助。

最佳答案

您必须使用 @InitBinder注释,因为在 Spring MVC 中,它总是为表单中的空白值返回 "" 。您必须在 Controller 中添加它。

例子:

@InitBinder    /* Converts empty strings into null when a form is submitted */
public void initBinder(WebDataBinder binder) {  
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));  
}

Source

关于forms - 在 Spring MVC 中将值设置为 NULL 而不是空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17647214/

相关文章:

php - 将表单中的数据存储到数据库中

javascript - apply() 的这种用法在 Javascript 中意味着什么

php - 在 CRM 应用程序数据库中存储电子邮件历史记录的最佳方法是什么

java - jBPM 和 JPA 事务管理器 : no local transaction to join

java - Spring aop 方面不执行

c# - 复选框通过在 asp.net 中取消选中而消失

java - 通过ajax发布表单并在play framework java中获取表单对象

javascript - 如何制作伪类:invalid apply to an input AFTER submitting a form

jquery - 如何在提交表单时使用 JQuery Ajax 发送请求而不重新加载页面

mysql - Spring Hibernate mysql 一对多