当前使用版本(必填,否则不予处理)

mybatis-plus-boot-starter 3.3.2

该问题是如何引起的?(确定最新版也有问题再提!!!)

我用的就是最新版

重现步骤(如果有就写完整)

pojo

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    @ApiModelProperty(value = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        // 这句成功打印了
        log.error("来了吗");
        this.strictInsertFill(metaObject, "created_at", LocalDateTime.class, LocalDateTime.now());
        this.strictUpdateFill(metaObject, "updated_at", LocalDateTime.class, LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updated_at", LocalDateTime.class, LocalDateTime.now());
    }
}

报错信息

测试插入时,自动填充错误:java.sql.SQLIntegrityConstraintViolationException: Column 'created_at' cannot be null

    @ApiOperation(value = "测试插入", notes = "测试插入", httpMethod = "POST")
    @RequestMapping("insert")
    public JSONResult<?> testInsert(){
        final Account account1 = new Account();
        account1.setUid(vip.qinqingquan.mh.utils.IdUtil.nextId());
        account1.setAccount("hello");
        account1.setEmail("hayto@foxmail.com");
//        account1.setCreatedAt(LocalDateTime.now());
        account1.setPassword(BCrypt.hashpw("123"));
//        account1.setUpdatedAt(LocalDateTime.now());
        account1.setIsDeleted(YesOrNo.NO.getValue());

        accountService.save(account1);
        return JSONResult.ok(account1);
    }

Comment From: haytoo1

POJO这样也试过,指定了字段名,仍然填充失败

    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT, value = "created_at")
    private LocalDateTime createdAt;

Comment From: qmdx

debug MyMetaObjectHandler 是否执行

Comment From: nieqiurong

strictInsertFill那参数是实体属性,不是数据库字段,用createdAt。

Comment From: haytoo1

strictInsertFill那参数是实体属性,不是数据库字段,用createdAt。

谢谢,果然是这个问题。大意了。

Comment From: vincentCheng

你好,我就是换成了驼峰命名法还是无法填充成功。