1. 程式人生 > >前臺日期字符串 提交到後臺 組裝entity失敗原因

前臺日期字符串 提交到後臺 組裝entity失敗原因

type reject des cte att ssp datetime exceptio and

錯誤信息

WARN - Resolved exception caused by Handler execution: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object ‘inStorage‘ on field ‘orderTime‘: rejected value [2017-07-20 21:49:45]; codes [typeMismatch.inStorage.orderTime,typeMismatch.orderTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [inStorage.orderTime,orderTime]; arguments []; default message [orderTime]]; default message [Failed to convert property value of type ‘java.lang.String‘ to required type ‘java.util.Date‘ for property ‘orderTime‘; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value ‘2017-07-20 21:49:45‘; nested exception is java.lang.IllegalArgumentException]

前臺提交的數據

code:001
businessName:11
businessLinkMan:小明
businessPhone:13545454545
orderTime:2017-07-20 21:59:54

對應出錯的entity

private String code;
private String businessName;
private String businessLinkMan;
private String businessPhone;

private Date orderTime;

對應正常的entity

private String code;
private String businessName;
private String businessLinkMan;
private String businessPhone;

@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date orderTime;


ps:可能是由於日期沒有加上格式,spring mvc 不知道如何把這個 “2017-07-20 21:59:54” 轉成日期 , 所以報錯。

前臺日期字符串 提交到後臺 組裝entity失敗原因