Field error in object ** on field **

错误信息:

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;

另外,指定的格式要和接受参数的格式一致,要不然还是会报同样的错误

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值