mp handler 字段填充

@Getter
@Setter
public class BaseEntity {
    @Schema(description = "创建人", accessMode = Schema.AccessMode.READ_ONLY)
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    private Long createBy;
    
    @Schema(description = "创建日期", accessMode = Schema.AccessMode.READ_ONLY)
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    
    @Schema(description = "更新人", accessMode = Schema.AccessMode.READ_ONLY)
    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
    private Long updateBy;
    
    @Schema(description = "更新日期", accessMode = Schema.AccessMode.READ_ONLY)
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;
    
    @Schema(description = "删除标志", accessMode = Schema.AccessMode.READ_ONLY)
    @TableField(value = "deleted", fill = FieldFill.INSERT)
    private Integer deleted;
}

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.strictInsertFill(metaObject, "createBy", String.class, SecurityUtils.getUserId().toString());
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "updateBy", String.class, SecurityUtils.getUserId().toString());
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "deleted", Integer.class, 0);
    }
    
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        this.strictUpdateFill(metaObject, "updateBy", String.class, SecurityUtils.getUserId().toString());
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
    }
}

你可能感兴趣的:(python,开发语言)