spring boot异常 required type 'java.util.Date' for property「终于解决」

Java (141) 2023-05-23 09:12

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说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]
	at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:157)

主要是时间格式问题。解决办法:在实体类的日期字段上加注解@DateTimeFormat(pattern = "yyyy-MM-dd")

spring boot异常 required type

↓ 点击下面的“了解更多”链接可查看详细。

发表回复