//递归删除菜单 @Override public void removeChildByIdGuli(String id) { //创建list集合,用于封装所有删除菜单的id值 List<String> idList = new ArrayList<>(); //向idList集合设置删除菜单id this.selectPermissionChildById(id,idList); //把当前id封装到id里面 idList.add(id); baseMapper.deleteBatchIds(idList); } //根据当前菜单id,查询菜单里面子菜单id,封装到list集合中 private void selectPermissionChildById(String id,List<String> idList) { //查询菜单里的子id QueryWrapper<Permission> wrapper = new QueryWrapper<>(); wrapper.eq("pid",id); wrapper.select("id"); List<Permission> childIdList = baseMapper.selectList(wrapper); //childIdList里面菜单id值获取出来,封装到idList里面,并且要做递归的操作 childIdList.stream().forEach(item -> { //封装idList里面去 idList.add(item.getId()); //递归查询 this.selectPermissionChildById(item.getId(), idList); }); }
给角色分配权限
//给角色分配菜单(权限) @Override public void saveRolePermissionRealtionShipGuli(String roleId, String[] permissionId) { //创建一个list集合用于最后封装添加数据 List<RolePermission> rolePermissionList = new ArrayList<>(); //遍历所有的菜单数组 for (String perId : permissionId) { RolePermission rolePermission = new RolePermission(); rolePermission.setRoleId(roleId); rolePermission.setPermissionId(perId); //封装到list集合 rolePermissionList.add(rolePermission); } //添加到角色菜单关系表 rolePermissionService.saveBatch(rolePermissionList); }