//预加载查询所有数据库数据 @PostConstruct private void init(){ menuList = roleInfoService.sysMenuListss(); }
//递归取 @GetMapping("qiaodq") public ApiResponse qiaodq(){ System.out.printf(menuList.toString()); List<Map<String, Object>> menuTreeList = createTree("0"); return new ApiResponse().success(menuTreeList); } private List<Map<String, Object>> createTree(String parentId) { List<Map<String, Object>> menuListTree = new ArrayList<>(); for (Map<String , Object> menu : menuList ) { //顶层 String upFatherId = menu.get("parentId").toString(); if (upFatherId.equals(parentId)){ String fatherId2 = menu.get("id").toString(); //再次调用取子集 List<Map<String, Object>> chidren = createTree(fatherId2); if (!chidren.isEmpty()){ menu.put("Nodes",chidren); } menuListTree.add(menu); } } return menuListTree; }