先参考官网https://baomidou.com/guide/logic-delete.html#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95
按照官网的说明,,步骤大致如下:
- 在实体类中设置需要作为逻辑删除的字段;
@TableLogic(value = "1", delval = "0")
private Integer deleted;
- 在service层中,创建查询条件,作为修改条件;
QueryWrapper<SpatialDataTag> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("spatial_data_id", id);
- Mapper层执行删除操作
this.baseMapper.delete(queryWrapper);
PS:数据库的删除字段,不能设置为关键字,如 delete
,不然 MyBatis-plus 会报错