您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“Spring Boot + Mybatis Plus怎么實現(xiàn)樹狀菜單”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
@TableField(exist = false) private Set<SysMenu> childrenList = new HashSet<>();
public SysMenu getChildrenList(SysMenu sysMenu, List<SysMenu> sysMenuList) { for (SysMenu menu : sysMenuList) { if (menu.getMenuParentId().equals(sysMenu.getId())) { sysMenu.getChildrenList().add(getChildrenList(menu, sysMenuList)); } } return sysMenu; }
public List<SysMenu> menuTree() { //獲取所有菜單 List<SysMenu> sysMenuList = list(new LambdaQueryWrapper<SysMenu>() //::在java8中的作用就是獲得方法 .eq(SysMenu::getMenuType, ResultConstant.MENU) ); //stream().filter()作用:過濾一個List對象,查找符合條件的對象集合 List<SysMenu> firstMenuList = sysMenuList.stream().filter //過濾出一級菜單 (s -> s.getMenuParentId().equals(ResultConstant.MENU_TOP)) // 返回list集合形式 .collect(Collectors.toList()); // 遍歷一級菜單,構(gòu)造菜單樹 for (SysMenu menu : firstMenuList) { getChildrenList(menu, sysMenuList); } return firstMenuList; }
菜單表如下
CREATE TABLE `sys_menu` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `menu_name` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '資源名稱', `menu_permission` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '權(quán)限', `menu_path` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '對應(yīng)url', `menu_parent_id` bigint(20) DEFAULT NULL COMMENT '父節(jié)點id', `menu_type` int(11) DEFAULT NULL COMMENT '菜單類型0菜單,1欄目類型', `order_num` int(11) DEFAULT NULL COMMENT '排序字段:值越小 順序越靠前', `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時間', `update_time` datetime DEFAULT NULL COMMENT '最后更新時間', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=75 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC COMMENT='菜單表'; -- ---------------------------- -- Records of sys_menu -- ---------------------------- INSERT INTO `sys_menu` VALUES ('1', '菜單樹', 'homePage:menuTree', '', '0', '0', '1', '2021-09-17 12:46:11', '2021-09-17 12:46:11'); INSERT INTO `sys_menu` VALUES ('2', '登錄模塊', null, null, '0', '0', '2', null, null); INSERT INTO `sys_menu` VALUES ('3', '登錄', null, '/login', '2', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('4', '修改密碼', null, '/login/updatePassword', '2', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('5', '修改個人信息', null, '/login/updateMessage', '2', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('6', '忘記密碼', 'login:forgetPassword', '/login/forgetPassword', '2', '1', '4', null, null); INSERT INTO `sys_menu` VALUES ('7', '消息通知管理', null, null, '0', '0', '3', null, null); INSERT INTO `sys_menu` VALUES ('8', '發(fā)布通知', 'notice:insert', '/notice/insert', '7', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('9', '修改通知', 'notice:update', '/notice/update', '7', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('10', '刪除通知', 'notice:delete', '/notice/delete', '7', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('11', '查看所有通知', 'notice:listAll', '/notice/listAll', '7', '1', '4', null, null); INSERT INTO `sys_menu` VALUES ('12', '查看本人已發(fā)布通知', 'notice:noticeList', '/notice/noticeList', '7', '1', '5', null, null); INSERT INTO `sys_menu` VALUES ('13', '查看所有已發(fā)布通知', 'notice:releasedNotice', '/notice/releasedNotice', '7', '1', '6', null, null); INSERT INTO `sys_menu` VALUES ('14', '系統(tǒng)管理', null, null, '0', '0', '4', null, null); INSERT INTO `sys_menu` VALUES ('15', '用戶管理', null, null, '14', '0', '1', null, null); INSERT INTO `sys_menu` VALUES ('16', '添加用戶', 'user:insert', '/user/insert', '15', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('17', '修改用戶信息', 'user:update', '/user/update', '15', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('18', '刪除用戶信息', 'user:delete', '/user/delete', '15', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('19', '查看所有用戶信息', 'user:listAll', '/user/listAll', '15', '1', '4', null, null); INSERT INTO `sys_menu` VALUES ('20', '分配用戶角色', 'user:setRole', '/user/setRole', '15', '1', '5', null, null); INSERT INTO `sys_menu` VALUES ('21', '角色管理', null, null, '14', '0', '2', null, null); INSERT INTO `sys_menu` VALUES ('22', '添加角色', 'role:insert', '/role/insert', '21', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('23', '修改角色信息', 'role:update', '/role/update', '21', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('24', '刪除角色', 'role:delete', '/role/delete', '21', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('25', '查看所有角色', 'role:listAll', 'role:listAll', '21', '1', '4', null, null); INSERT INTO `sys_menu` VALUES ('26', '設(shè)置角色權(quán)限', 'role:setMenu', '/role/setMenu', '21', '1', '5', null, null); INSERT INTO `sys_menu` VALUES ('27', '查看自己是否各個擁有角色', 'role:myRole', '/role/myRole', '21', '1', '6', null, null); INSERT INTO `sys_menu` VALUES ('28', '權(quán)限管理', null, null, '14', '0', '3', null, null); INSERT INTO `sys_menu` VALUES ('29', '添加權(quán)限', 'menu:insert', '/menu/insert', '28', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('30', '修改權(quán)限', 'menu:update', '/menu/update', '28', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('31', '刪除權(quán)限', 'menu:delete', '/menu/delete', '28', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('32', '查看所有權(quán)限', 'menu:listAll', '/menu/listAll', '28', '1', '4', null, null); INSERT INTO `sys_menu` VALUES ('33', '登錄日志', '', '', '14', '0', '4', null, null); INSERT INTO `sys_menu` VALUES ('34', '操作日志', '', '', '14', '0', '5', null, null); INSERT INTO `sys_menu` VALUES ('35', '信息管理', null, null, '0', '0', '5', null, null); INSERT INTO `sys_menu` VALUES ('36', '查看所有學(xué)生信息', 'student:listAll', '/student/listAll', '35', '0', '1', null, null); INSERT INTO `sys_menu` VALUES ('37', '查看所有教師信息', 'teacher:listAll', '/teacher/listAll', '35', '0', '2', null, null); INSERT INTO `sys_menu` VALUES ('38', '班級信息管理', null, null, '35', '0', '3', null, null); INSERT INTO `sys_menu` VALUES ('39', '添加班級', 'class:insert', '/class/insert', '38', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('40', '修改班級信息', 'class:update', '/class/update', '38', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('41', '刪除班級', 'class:delete', '/class/delete', '38', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('42', '查看所有班級', 'class:listAll', '/class/listAll', '38', '1', '4', null, null); INSERT INTO `sys_menu` VALUES ('43', '專業(yè)管理', null, null, '35', '0', '4', null, null); INSERT INTO `sys_menu` VALUES ('44', '添加專業(yè)', 'major:insert', '/major/insert', '43', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('45', '修改專業(yè)信息', 'major:update', '/major/update', '43', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('46', '刪除專業(yè)', 'major:delete', '/major/delete', '43', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('47', '查看所有專業(yè)', 'major:listAll', '/major/listAll', '43', '1', '4', null, null); INSERT INTO `sys_menu` VALUES ('48', '學(xué)院管理', null, null, '35', '0', '5', null, null); INSERT INTO `sys_menu` VALUES ('49', '添加學(xué)院', 'institute:insert', '/institute/insert', '48', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('50', '修改學(xué)院信息', 'institute:update', '/institute/update', '48', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('51', '刪除學(xué)院', 'institute:delete', '/institute/delete', '48', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('52', '查看所有學(xué)院', 'institute:listAll', '/institute/listAll', '48', '1', '4', null, null); INSERT INTO `sys_menu` VALUES ('53', '上課管理', null, null, '0', '0', '6', null, null); INSERT INTO `sys_menu` VALUES ('54', '課程表', null, null, '53', '0', '1', null, null); INSERT INTO `sys_menu` VALUES ('55', '添加課程', 'lesson:insert', '/lesson/insert', '54', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('56', '修改課程', 'lesson:update', '/lesson/update', '54', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('57', '刪除課程', 'lesson:delete', '/lesson/delete', '54', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('58', '查看所有課程', 'lesson:listAll', '/lesson/listAll', '54', '1', '4', null, null); INSERT INTO `sys_menu` VALUES ('59', '考勤管理', null, null, '53', '0', '2', null, null); INSERT INTO `sys_menu` VALUES ('60', '教師發(fā)放簽到', 'lesson:startCourse', '/lesson/startCourse', '59', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('61', '學(xué)生簽到', 'attendance:studentSignIn', '/attendance/studentSignIn', '59', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('62', '查看考勤信息', 'attendance:listAll', '/attendance/listAll', '59', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('63', '請假管理', null, null, '0', '0', '7', null, null); INSERT INTO `sys_menu` VALUES ('64', '學(xué)生請假', 'leave:studentLeave', '/leave/studentLeave', '63', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('65', '修改請假信息', 'leave:studentUpdate', '/leave/studentUpdate', '63', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('66', '刪除請假', 'leave:studentDelete', '/leave/studentDelete', '63', '1', '3', null, null); INSERT INTO `sys_menu` VALUES ('67', '查看所有請假信息', 'leave:listAll', '/leave/listAll', '63', '1', '4', null, null); INSERT INTO `sys_menu` VALUES ('68', '請假審批', 'leave:approval', '/leave/approval', '63', '1', '5', null, null); INSERT INTO `sys_menu` VALUES ('69', '查看登錄日志', 'loginLog:listAll', '/loginLog/listAll', '33', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('70', '刪除登錄日志', 'loginLog:delete', '/loginLog/delete', '33', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('71', '查看操作日志', 'operateLog:listAll', '/operateLog/listAll', '34', '1', '1', null, null); INSERT INTO `sys_menu` VALUES ('72', '刪除操作日志', 'operateLog:delete', '/operateLog/delete', '34', '1', '2', null, null); INSERT INTO `sys_menu` VALUES ('73', '分配教師班級', 'teacher:assignTeacherClasses', '/teacher/assignTeacherClasses', '38', '1', '5', null, null); INSERT INTO `sys_menu` VALUES ('74', '查看教師是否任教各個班級', 'teacher:myClass', '/teacher/myClass', '38', '1', '6', null, null);
效果如下
“Spring Boot + Mybatis Plus怎么實現(xiàn)樹狀菜單”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。