错误消息:
Field error in object 'user' on field 'birthday': rejected value [2001-02-14]; 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 '2001-02-14'; nested exception is java.lang.IllegalArgumentException]]
可以在实体类上加上注解解决无法自动转换的问题。
代码示例:
@DateTimeFormat( pattern = "yyyy-MM-dd") private Date birthday;