关于springboot里面前端ajax出现传值给后端,日期格式的数据出现错误
Field error in object 'propertyNotice' on field 'release_date': rejected value [Sat Nov 26 2022 08:00:00 GMT+0800 (中国标准时间)]; codes [typeMismatch.propertyNotice.release_date,typeMismatch.release_date,typeMismatch.java.sql.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [propertyNotice.release_date,release_date]; arguments []; default message [release_date]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Date' for property 'release_date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.sql.Date] for value 'Sat Nov 26 2022 08:00:00 GMT+0800 (中国标准时间)'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [Sat Nov 26 2022 08:00:00 GMT+0800 (中国标准时间)]]]
解决办法
1.首先要在实体类中添加注解@Datetimeformat 指明格式
2.将mybatis生成的实体类中日期格式转变为java.util.Date