码迷,mamicode.com
首页 > 其他好文 > 详细

前台日期字符串 提交到后台 组装entity失败原因

时间:2017-07-21 00:02:34      阅读:1741      评论:0      收藏:0      [点我收藏+]

标签:string   []   cut   one   reject   pat   exce   code   version   

错误信息

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失败原因

标签:string   []   cut   one   reject   pat   exce   code   version   

原文地址:http://www.cnblogs.com/cppwen/p/7214818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!