springmvc提交表单报错:Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'

springmvc在提交表单时报错,具体报错如下:

Field error in object 'financeDetailed' on field 'actionDate': rejected value [2016-02-22]; codes [typeMismatch.financeDetailed.actionDate,typeMismatch.actionDate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [financeDetailed.actionDate,actionDate]; arguments []; default message [actionDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'actionDate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'actionDate': no matching editors or conversion strategy found]] with root cause

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors

以上错误主要原因是,springmvc的controller把date类型当成string了,要解决Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'的问题,可以参考本站的以下文章:

springmvc接收date类型参数:利用spring的DateTimeFormat注解

springmvc接收date类型参数:在controller中使用initBinder注解

如若转载,请注明出处:http://www.codingwhy.com/view/765.html

联系我们

在线咨询: 点击这里给我发消息

邮件:731000228@qq.com