springboot遇到日期类型注入不进数据库

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;```

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值