springboot自动装备date类型报错问题

错误消息:

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;

 

posted on 2019-06-20 21:38  荆棘人  阅读(791)  评论(0)    收藏  举报

导航