Field error in object 'custom' on field 'rentCarTime': rejected value [2021-07-16 13:38]; codes [typeMismatch.custom.rentCarTime,typeMismatch.rentCarTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [custom.rentCarTime,rentCarTime]; arguments []; default message [rentCarTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'rentCarTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.baomidou.mybatisplus.annotation.TableField @com.alibaba.fastjson.annotation.JSONField java.util.Date] for value '2021-07-16 13:38'; nested exception is java.lang.IllegalArgumentException]
当你的字段出现这种日期型无法注入数据库的时候,上面显示的是拒绝注入,可是自己后端明明写了格式转换,但是还是出了这种错误。
还好寻找了好几个小时终于找到问题所在,实体类的日期字段 @DateTimeFormat(pattern = “yyyy-MM-dd”) 必须加这个注解啊 以后只要springboot+mybatisPlus出这种问题就找这里
//必须加这句代码,无论你后台写格式转换这些都必须加这句代码,实体类数据注入必须这句
@DateTimeFormat(pattern = "yyyy-MM-dd")
// @JSONField(format ="yyyy-MM-dd" )
private Date rentCarTime;
@TableField("payMoney")
private BigDecimal payMoney;
@TableField("returnCarTime")
@DateTimeFormat(pattern = "yyyy-MM-dd")
// @JSONField(format = "yyyy-MM-dd HH:mm")
private Date returnCarTime;```