一、背景
使用easyui框架写from表单时,发送ajax请求,data等于$("#addDialog form").serialize(),提交后结果为400
浏览器控制台信息:
Failed to convert property value of type 'java.lang.String' to required type 、'java.util.Date' for property
'followOrderStudentVo.followTime';nested exception is org.springframework.core.convert.
ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2018-09-13';
nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2018-09-13]",
"objectName":"followStudentDto","field":"followOrderStudentVo.followTime",
"rejectedValue":"2018-09-13","bindingFailure":true,"code":"typeMismatch"}],
"message":"Validation failed for object='followStudentDto'.
二、原因
$(from).serialize()方法将原本的时间框中的Date类型的数据序列化为String类型,后台在自动装配时setter方法的类型不匹配
这里要说下easyui:easyui-datebox和easyui-datetimebox的区别了
easyui-datebox会转为String
easyui-datetimebox会转为Date
三、解决办法
将前端页面中时间框input的class属性easyui-datebox换为easyui-datetimebox就行了