递归删除菜单
程序员文章站
2022-04-30 22:13:32
...
//============递归删除菜单==================================
@Override
public void removeChildByIdGuli(String id) {
//1 创建list集合,用于封装所有删除菜单id值
List<String> idList = new ArrayList<>();
//2 向idList集合设置删除菜单id
this.selectPermissionChildById(id,idList);//找到当前菜单的子菜单 把结果id封装到idlist里面去
//把当前id封装到list里面
idList.add(id);//现在把当前id封装进去 之前都是子菜单的id
baseMapper.deleteBatchIds(idList);
}
//2 根据当前菜单id,查询菜单里面子菜单id,封装到list集合
private void selectPermissionChildById(String id, List<String> idList) {
//查询菜单里面子菜单id
QueryWrapper<Permission> wrapper = new QueryWrapper<>();
wrapper.eq("pid",id);
wrapper.select("id");//我们只想查询id 所以只需要查询指定列的值
List<Permission> childIdList = baseMapper.selectList(wrapper);//当前菜单的所有子菜单
//把childIdList里面菜单id值获取出来,封装idList里面,做递归查询
childIdList.stream().forEach(item -> {//遍历集合得到每一个对象item
//封装idList里面
idList.add(item.getId());
//递归查询
this.selectPermissionChildById(item.getId(),idList);
});
}