首页 > 其他分享 > Column 'gmt_create' cannot be null创建时间不允许为空[Mybatis-plus自动填充]

Column 'gmt_create' cannot be null创建时间不允许为空[Mybatis-plus自动填充]

时间:2023-03-13 21:56:02浏览次数:38  
标签:填充 Column create cannot 时间 为空 Mybatis null

首先确认各项代码部分无误
1、创建包handler,创建自动填充类 MyMetaObjectHandler:

2、在实体类中添加注解

3、Controller方法定义

以上代码都没问题,目的是为了在不填时间的情况希望能够自动插入当下时间,但是依然在Swagger测试中不填时间会报错,显示 Column 'gmt_create' cannot be null。

经测试,如果填入错误的时间,但是要是正确的时间格式,那么在数据库中插入的时间不是错误的时间,而是当下的时间。
也就是说,Mybatis-plus的时间填充是在sql语句之后的,在发现sql语句中时间为空就报错了。

解决办法:修改表中有关时间的字段属性,将其设置为允许为空。

标签:填充,Column,create,cannot,时间,为空,Mybatis,null
From: https://www.cnblogs.com/Tetsuya/p/17213047.html

相关文章