在Spring中,从jsp页面上的日期选择器读取后,web控制器中的mvc应用程序日期值被接收为NULL

我有一个使用jquery的spring mvc web应用程序。 我使用spring标签直接将字段映射到pojo。 这样日期就会映射到相应的字段。

在Spring MVC中,有日期选择器的领域正在以正确的格式阅读日期:

 $(document).ready(function () { $("#deliveryDate").datepicker({ minDate: 0 }); }); $(document).ready(function () { $("#quoationStartDate").datepicker({ minDate: 0 }); });  

这是JSP上的输入参数:

 

使用@Initbinder来解析日期

 @InitBinder public void dateBinder(WebDataBinder bind) { System.out.println("In Binder"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-mm-yyyy"); simpleDateFormat.setLenient(false); bind.registerCustomEditor(Date.class, new CustomDateEditor(simpleDateFormat, true)); } 

但是在表单发布操作之后,控制器中收到的日期值为null。 必须解决这个问题,这样我才能收到dd-MM-yyyy格式的日期,这个日期可以存储到数据库中。

将html输入类型从type =“Date”更改为type =“text”后工作。

Interesting Posts