问题描述:
在input type="date"时提交后出现转换异常
Field error in object 'employee' on field 'birth': rejected value [2019-08-17]; codes [typeMismatch.employee.birth,typeMismatch.birth,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [employee.birth,birth]; arguments []; default message [birth]]; default message [Failed to convert value of type 'java.lang.String[]' to required type 'java.util.Date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2019-08-17'; nested exception is java.lang.IllegalArgumentException]]
看到这个当场就感到疑惑,在date控件中,默认的不是以/的方式将date类型的字符串传递给后台的嘛,怎么会出现以-类型的日期字符串,带着这个疑问,我先将date改成text类型看看输入'2019-08-17'和'2019/08/17'是否还会报错
当输入'2019-08-17'报了和上面一样的错误,接着
当输入'2019/08/17'就跳转过来了
fsdf.PNG
就说明确实是我想错了,date类型传递过来的字符串是以-连接的
hhhh,一失足成千古恨哦~
所以现在就知道了解决方案了
可以配置date-format=yyyy-MM-dd就没有问题了