错误信息:
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 2 errors
Field error in object 'tbHonorVO' on field 'attachments[0].createtime': rejected value [2019-06-28 10:10:44]; codes [typeMismatch.tbHonorVO.attachments[0].createtime,typeMismatch.tbHonorVO.attachments.createtime,typeMismatch.attachments[0].createtime,typeMismatch.attachments.createtime,typeMismatch.createtime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [tbHonorVO.attachments[0].createtime,attachments[0].createtime]; arguments []; default message [attachments[0].createtime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'attachments[0].createtime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Column java.util.Date] for value '2019-06-28 10:10:44'; nested exception is java.lang.IllegalArgumentException]
...
后端使用SpringBoot框架,前端传过来时间参数出现的不匹配问题。后端接受的参数类型是Date,前端发过来是String类型,所以报这个错误。
解决方法:
在接受参数类对应的字段上加@DateTimeFormat注解,并且指定格式,例如
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @Column(name = "EffectiveTime") private Date effectivetime;
另外,指定的格式要和接受参数的格式一致,要不然还是会报同样的错误