✅P50_三级分类-删除-逻辑删除
大约 1 分钟
物理删除
cfmall-product/src/main/java/com/gyz/cfmall/product/controller/CategoryController.java
@RestController
@RequestMapping("product/category")
public class CategoryController {
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] catIds) {
categoryService.removeMenuByIds(Arrays.asList(catIds));
return R.ok();
}
}
cfmall-product/src/main/java/com/gyz/cfmall/product/service/impl/CategoryServiceImpl.java
@Service("categoryService")
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity> implements CategoryService {
@Override
public void removeMenuByIds(List<Long> asList) {
//TODO 检查当前删除的菜单,是否被别的地方引用
//逻辑删除
baseMapper.deleteBatchIds(asList);
}
}
删除测试
发现数据库中cat_id
=1432的数据被删除了。
逻辑删除
1、在逻辑删除字段上加上注解 @TableLogic
cfmall-product/src/main/java/com/gyz/cfmall/product/entity/CategoryEntity.java
/**
* 是否显示[0-不显示,1显示]
*/
@TableLogic(value = "1",delval = "0")
private Integer showStatus;
2、配置 application.yml
cfmall-product/src/main/resources/application.yml
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
#设置实体类的自增主键
global-config:
db-config:
id-type: auto
#逻辑删除
logic-delete-value: 1
logic-not-delete-value: 0
3、测试
测试发现 show_status
字段会由1变成0
日志打印SQL语句
cfmall-product/src/main/resources/application.yml
# 配置日志级别
logging:
level:
com.gyz.cfmall: debug