逻辑删除:不仅仅支持flag删除标记字段,还可自动填充删除时间字段,flag字段可时间,可数字类型,可boolean!
@Data @Table public class LogicDeleteTest { @TableId private Long id; private String name; private LocalDateTime deleteTime; @LogicDelete(beforeValue = "0", afterValue = "1", deleteTimeField = "deleteTime") private Byte deleted; }
1. @LogicDelete 属性 beforeValue 未删除前的值,只能是固定值;时间类型的逻辑,可不填 2. @LogicDelete 属性 afterValue 删除后的值,可固定值或者动态值 例如 afterValue = "{NOW}",目前支持LocalDateTime,Date,Long,Integer,框架自动给值 3。 @LogicDelete 属性 deleteTimeField 逻辑删除的时间字段,可不填,填了系统自动update 时 设置删除时间,deleteTimeField对应的字段类型 支持:LocalDateTime,Date,Long,Integer类型 4. 逻辑删除全局开关(默认开) MybatisMpConfig.setLogicDeleteSwitch(true); 5 逻辑删除-局部开关 try (LogicDeleteSwitch ignored = LogicDeleteSwitch.with(false)) { logicDeleteTestMapper.getById(1); } 上面代码必须try (LogicDeleteSwitch ignored = LogicDeleteSwitch.with(false)) 或 下面的更简单: LogicDeleteTest logicDeleteTest = LogicDeleteUtil.execute(false, () -> { return logicDeleteTestMapper.getById(1); });