From 259741fc88c1377b9b1120dab1558da0565a6bbc Mon Sep 17 00:00:00 2001 From: duanledexianxianxian Date: Mon, 13 Jan 2020 01:14:32 +0800 Subject: [PATCH] add:menu --- .../java/com/duanledexianxianxian/demo/Application.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/menu/src/main/java/com/duanledexianxianxian/demo/Application.java b/menu/src/main/java/com/duanledexianxianxian/demo/Application.java index 7291625..47325f1 100644 --- a/menu/src/main/java/com/duanledexianxianxian/demo/Application.java +++ b/menu/src/main/java/com/duanledexianxianxian/demo/Application.java @@ -50,17 +50,23 @@ public class Application { } } + /** + * 平级列表转成树结构 + * @param menuList + * @return + */ private static MenuVO getTreeMenuVO(List menuList) { if (CollectionUtils.isEmpty(menuList)) { return null; } List menuVOList = Lists.newArrayList(); + // 类型转换 一层循环 menuList.forEach(x -> { MenuVO menuVO = new MenuVO(); BeanUtils.copyProperties(x, menuVO); menuVOList.add(menuVO); }); - // 转成map + // 转成map 二层循环 一层与二层可以合并 Map menuMap = menuVOList.stream().collect(Collectors.toMap(MenuVO::getMenuCode, x -> x)); // 构建根节点 MenuVO menuVO = new MenuVO(); @@ -68,6 +74,7 @@ public class Application { menuVO.setMenuCode("root"); menuVO.setMenuTitle("根节点"); + // 转换逻辑 三层循环 for (MenuVO menu : menuVOList) { if (menuMap.containsKey(menu.getParentMenuCode())) { if (menuMap.get(menu.getParentMenuCode()).getChildren() == null) { -- GitLab