springmvc关于前台日期作为实体类对象参数类型转换错误

时间:2017-06-24 19:18:12   收藏:0   阅读:3329

页面报错:

技术分享

 

后台错误:

Field error in object ‘user‘ on field ‘birthday‘: rejected value [2013-06-24]; codes [typeMismatch.user.birthday,typeMismatch.birthday,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.birthday,birthday]; arguments []; default message [birthday]]; default message [Failed to convert property value of type ‘java.lang.String‘ to required type ‘java.util.Date‘ for property ‘birthday‘; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type java.util.Date for value ‘2013-06-24‘; nested exception is java.lang.IllegalArgumentException]

 

解决方案:在对应的实体类属性上加入   @DateTimeFormat(pattern = "yyyy-MM-dd")

技术分享

 

原文:http://www.cnblogs.com/wiseroll/p/7074070.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!