From 6b6b4d9514eb987554902ae0b7adfacc53d39985 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Fri, 15 Mar 2019 19:25:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=BE=97=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E6=9D=83=E9=99=90=E6=97=B6=EF=BC=8C=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/controller/admins/AdminController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java index 4f5a4744b..041671d41 100644 --- a/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java +++ b/admin/admin-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java @@ -48,7 +48,9 @@ public class AdminController { public CommonResult> menuResourceTree() { List resources = resourceService.getResourcesByTypeAndRoleIds(ResourceConstants.TYPE_MENU, AdminSecurityContextHolder.getContext().getRoleIds()); // 创建 AdminMenuTreeNodeVO Map - Map treeNodeMap = resources.stream().collect(Collectors.toMap(ResourceBO::getId, ResourceConvert.INSTANCE::convert)); +// Map treeNodeMap = resources.stream().collect(Collectors.toMap(ResourceBO::getId, ResourceConvert.INSTANCE::convert)); + Map treeNodeMap = new LinkedHashMap<>(); // 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。 + resources.stream().sorted(Comparator.comparing(ResourceBO::getSort)).forEach(resourceBO -> treeNodeMap.put(resourceBO.getId(), ResourceConvert.INSTANCE.convert(resourceBO))); // 处理父子关系 treeNodeMap.values().stream() .filter(node -> !node.getPid().equals(ResourceConstants.PID_ROOT)) @@ -64,7 +66,7 @@ public class AdminController { // 获得到所有的根节点 List rootNodes = treeNodeMap.values().stream() .filter(node -> node.getPid().equals(ResourceConstants.PID_ROOT)) - .sorted(Comparator.comparing(AdminMenuTreeNodeVO::getSort)) +// .sorted(Comparator.comparing(AdminMenuTreeNodeVO::getSort)) .collect(Collectors.toList()); return CommonResult.success(rootNodes); }