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


错误信息

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” 转成日期 , 所以报错。

优质内容筛选与推荐>>
1、office2010的破解工具
2、获得栈的位置
3、CTPN-自然文本场景检测代码阅读笔记
4、JVM调优-Jstack线程分析
5、MyEclipse从数据库反向生成实体类通过Hibernate的方式----mysql数据库实例


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号