前言
本系列博客基于B站的云e办管理系统,前端和后端我都自己敲了一遍,这里做一个学习记录。云e办的原始视频链接如下:https://www.bilibili.com/video/BV1Ai4y1P7Tk?p=1
新建一个权限组Controller
package com.xxxx.server.controller.PermissController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.PeekingIterator;
import com.xxxx.server.pojo.Menu;
import com.xxxx.server.pojo.MenuRole;
import com.xxxx.server.pojo.RespBean.RespBean;
import com.xxxx.server.pojo.Role;
import com.xxxx.server.service.IMenuRoleService;
import com.xxxx.server.service.IMenuService;
import com.xxxx.server.service.IRoleService;
import com.xxxx.server.service.impl.MenuServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.PipedReader;
import java.util.List;
import java.util.stream.Collectors;
/**
*
* 权限组
* @author LinLinD
* @Create 2022-04-20-0:40
*/
@RestController
@RequestMapping("/system/basic/permiss")
public class PermissController {
@Autowired
private IRoleService roleService;
@Autowired
private IMenuService menuService;
@Autowired
private IMenuRoleService menuRoleService;
@ApiOperation(value = "获取所有角色")
@GetMapping("/")
public List<Role> getAllRoles() {
return roleService.list();
}
@ApiOperation(value = "添加角色")
@PostMapping("/")
public RespBean addRole(@RequestBody Role role) {
if (!role.getName().startsWith("ROLE_")) {
role.setName("ROLE_" + role.getName());
}
if (roleService.save(role)) {
return RespBean.success("添加成功!");
}
return RespBean.error("添加失败!");
}
@ApiOperation(value = "删除角色")
@DeleteMapping("/role/{rid}")
public RespBean deleteRole(@PathVariable Integer rid) {
if (roleService.removeById(rid)) {
return RespBean.success("删除成功!");
}
return RespBean.error("删除失败!");
}
@ApiOperation(value = "查询所有菜单")
@GetMapping("/menus")
public List<Menu> getAllMenus() {
return menuService.getAllMenus();
}
@ApiOperation(value = "根据角色id查询菜单id")
@GetMapping("/mid/{rid}")
public List<Integer> getMidByRid(@PathVariable Integer rid) {
return menuRoleService.list(new QueryWrapper<MenuRole>().eq("rid",rid))
.stream()
.map(MenuRole::getMid)
.collect(Collectors.toList());
}
@ApiOperation(value = "更新角色菜单")
@PutMapping("/")
public RespBean updateMenuRole(Integer rid,Integer[] mids) {
return menuRoleService.updateMenuRole(rid,mids);
}
}
其中菜单的功能需要进一步写sql语句
首先是查询所有菜单的功能,在菜单服务类上定义
服务实现类实现
Mapper接口
mapper.xml文件