情景说明:
采用mybatis-gen生成的bean类,数据库中的Datetime字段映射为Date字段
页面上传来的内容是 yyyy-MM-dd 日期格式,用@Past注解日期,如下
@Past(message = "时间有误")
//@DateTimeFormat(pattern="yyyy-MM-dd")
private Date createTime;
报错信息如下:
Failed to convert property value of type java.lang.String to required type java.util.Date for property createTime; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.validation.constraints.Past java.util.Date for value 2014-05-21; nested exception is java.lang.IllegalArgumentException
解决方案:应用DateTimeFormat注解,把上面注释的代码取消注释。