MybatisPlus逻辑删除@TableLogic及日期的自动填充注解@TableField


    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT) //插入数据自动填充
    private Date createTime;

    @ApiModelProperty(value = "更新时间")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) //更新数据自动填充
    private Date updateTime;

    @ApiModelProperty(value = "删除标记")
    @TableLogic //逻辑删除(默认0可用 1不可以)
    private Integer isDeleted;

自动添加时间还要添加一个实现MetaObjectHandler接口的处理器

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    //对应插入数据时自动填充
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime",new Date(), metaObject);
        this.setFieldValByName("updateTime",new Date(), metaObject);
    }

    //对应更新数据时自动更新
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime",new Date(), metaObject);
    }
}