🚀 菜单管理
This commit is contained in:
parent
08d0d6bd09
commit
8f20d4c82f
|
@ -34,5 +34,11 @@
|
|||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.atguigu.common.utlis;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MenuHelper {
|
||||
/**
|
||||
* 构建树型结构
|
||||
*
|
||||
* @param sysMenuList 系统菜单列表
|
||||
* @return 菜单结构列表
|
||||
*/
|
||||
public static List<SysMenu> buildTree(List<SysMenu> sysMenuList) {
|
||||
ArrayList<SysMenu> tress = new ArrayList<>();
|
||||
// 把菜单数据进行遍历
|
||||
sysMenuList.forEach(sysMenu -> {
|
||||
if (sysMenu.getParentId() == 0) tress.add(getChildren(sysMenu, sysMenuList));
|
||||
});
|
||||
return tress;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建递归循环
|
||||
*
|
||||
* @param sysMenu 当前菜单对象
|
||||
* @param sysMenuList 全部菜单列表
|
||||
* @return 菜单
|
||||
*/
|
||||
private static SysMenu getChildren(SysMenu sysMenu, List<SysMenu> sysMenuList) {
|
||||
// 遍历所有菜单数据,判断id和parentID对应关系
|
||||
sysMenu.setChildren(new ArrayList<>());
|
||||
|
||||
sysMenuList.forEach(menu -> {
|
||||
if (menu.getChildren() == null) menu.setChildren(new ArrayList<>());
|
||||
if (sysMenu.getId().equals(menu.getParentId())) {
|
||||
sysMenu.getChildren().add(getChildren(menu, sysMenuList));
|
||||
}
|
||||
});
|
||||
|
||||
return sysMenu;
|
||||
}
|
||||
}
|
|
@ -55,7 +55,7 @@ public class CodeGet {
|
|||
private static StrategyConfig getStrategyConfig() {
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
// TODO 要生成的表
|
||||
strategy.setInclude("sys_user", "sys_role","sys_user_role");
|
||||
strategy.setInclude("sys_menu", "sys_role_menu");
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);// 数据库表映射到实体的命名策略
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 数据库表字段映射到实体的命名策略
|
||||
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,57 @@
|
|||
package com.atguigu.auth.controller;
|
||||
|
||||
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.common.result.Result;
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Tag(name = "菜单管理")
|
||||
@RestController
|
||||
@RequestMapping("/admin/system/sysMenu")
|
||||
public class SysMenuController {
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
@ApiOperation(value = "获取菜单")
|
||||
@GetMapping("findNodes")
|
||||
public Result<List<SysMenu>> findNodes() {
|
||||
List<SysMenu> list = sysMenuService.findNodes();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增菜单")
|
||||
@PostMapping("save")
|
||||
public Result<SysMenu> save(@RequestBody SysMenu permission) {
|
||||
sysMenuService.save(permission);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改菜单")
|
||||
@PutMapping("update")
|
||||
public Result<SysMenu> updateById(@RequestBody SysMenu permission) {
|
||||
sysMenuService.updateById(permission);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除菜单")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result<SysMenu> remove(@PathVariable Long id) {
|
||||
sysMenuService.removeById(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.atguigu.auth.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/auth/sys-role-menu")
|
||||
public class SysRoleMenuController {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.auth.mapper;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.auth.mapper;
|
||||
|
||||
import com.atguigu.model.system.SysRoleMenu;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.atguigu.auth.service;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysMenuService extends IService<SysMenu> {
|
||||
|
||||
/**
|
||||
* 获取菜单
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> findNodes();
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.atguigu.auth.service;
|
||||
|
||||
import com.atguigu.model.system.SysRoleMenu;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysRoleMenuService extends IService<SysRoleMenu> {
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.atguigu.auth.service.impl;
|
||||
|
||||
import com.atguigu.auth.mapper.SysMenuMapper;
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.common.utlis.MenuHelper;
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||
|
||||
/**
|
||||
* 获取菜单
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findNodes() {
|
||||
return MenuHelper.buildTree(list());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.atguigu.auth.service.impl;
|
||||
|
||||
import com.atguigu.auth.mapper.SysRoleMenuMapper;
|
||||
import com.atguigu.auth.service.SysRoleMenuService;
|
||||
import com.atguigu.model.system.SysRoleMenu;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.atguigu.auth.mapper.SysMenuMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.atguigu.auth.mapper.SysRoleMenuMapper">
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue