说明:
只对自动注入的 sql 起效:
where条件过滤掉已删除数据,且使用 wrapper.entity 生成的 where 条件会忽略该字段where条件防止更新到已删除数据,且使用 wrapper.entity 生成的 where 条件会忽略该字段例如:
update user set deleted=1 where id = 1 and deleted=0 select id,name,deleted from user where deleted=0 字段类型支持说明:
Integer,Boolean,LocalDateTime)datetime,逻辑未删除值和已删除值支持配置为字符串null,另一个值支持配置为函数来获取值如now() 附录:
com.baomidou.mybatisplus.core.config.GlobalConfig$DbConfig例如: application.yml
mybatis-plus:
global-config:
db-config:
logic-delete-field: flag # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2)
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
@TableLogic注解@TableLogic
private Integer deleted;
insert前自己 set值 update方法并: UpdateWrapper.set(column, value)(推荐) update方法并: UpdateWrapper.setSql("column=value") com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill 并使用(推荐)