How to implement logical deletion in MybatisPlus?

MybatisPlus can implement logical deletion through the following steps:

  1. Flag for deletion
  2. TableLogic
@TableLogic
private Integer deleteFlag;
  1. configuration file for an application
  2. properties file for the application
mybatis-plus:
  global-config:
    db-config:
      logic-delete-field: deleteFlag  # 配置逻辑删除字段
      logic-delete-value: 1           # 配置逻辑删除的值
      logic-not-delete-value: 0       # 配置未删除的值
  1. Mapping base
  2. a designated storage location
@Repository
public interface UserMapper extends BaseMapper<User> {
}
  1. removeById
@Autowired
private UserMapper userMapper;

public void deleteUserById(Long id) {
    userMapper.deleteById(id);
}

Please note that logical deletion does not actually remove data from the database, but instead updates the value of the deleteFlag field to the configured logical deletion value.

bannerAds