spring boot異常 required type 'java.util.Date' for property

springboot運行時異常:

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'staffInfo' on field 'birthday': rejected value [1958-01-01]; codes [typeMismatch.staffInfo.birthday,typeMismatch.birthday,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [staffInfo.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 [@io.swagger.annotations.ApiModelProperty @com.baomidou.mybatisplus.annotations.TableField java.util.Date] for value '1958-01-01'; nested exception is java.lang.IllegalArgumentException]
\tat org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:157)

主要是時間格式問題。解決辦法:在實體類的日期字段上加註解@DateTimeFormat(pattern = "yyyy-MM-dd")

spring boot異常 required type 'java.util.Date' for property

↓ 點擊下面的“瞭解更多”鏈接可查看詳細。


分享到:


相關文章: