Commit 259741fc authored by duanledexianxianxian's avatar duanledexianxianxian 😁

add:menu

parent a208fd3f
...@@ -50,17 +50,23 @@ public class Application { ...@@ -50,17 +50,23 @@ public class Application {
} }
} }
/**
* 平级列表转成树结构
* @param menuList
* @return
*/
private static MenuVO getTreeMenuVO(List<Menu> menuList) { private static MenuVO getTreeMenuVO(List<Menu> menuList) {
if (CollectionUtils.isEmpty(menuList)) { if (CollectionUtils.isEmpty(menuList)) {
return null; return null;
} }
List<MenuVO> menuVOList = Lists.newArrayList(); List<MenuVO> menuVOList = Lists.newArrayList();
// 类型转换 一层循环
menuList.forEach(x -> { menuList.forEach(x -> {
MenuVO menuVO = new MenuVO(); MenuVO menuVO = new MenuVO();
BeanUtils.copyProperties(x, menuVO); BeanUtils.copyProperties(x, menuVO);
menuVOList.add(menuVO); menuVOList.add(menuVO);
}); });
// 转成map // 转成map 二层循环 一层与二层可以合并
Map<String, MenuVO> menuMap = menuVOList.stream().collect(Collectors.toMap(MenuVO::getMenuCode, x -> x)); Map<String, MenuVO> menuMap = menuVOList.stream().collect(Collectors.toMap(MenuVO::getMenuCode, x -> x));
// 构建根节点 // 构建根节点
MenuVO menuVO = new MenuVO(); MenuVO menuVO = new MenuVO();
...@@ -68,6 +74,7 @@ public class Application { ...@@ -68,6 +74,7 @@ public class Application {
menuVO.setMenuCode("root"); menuVO.setMenuCode("root");
menuVO.setMenuTitle("根节点"); menuVO.setMenuTitle("根节点");
// 转换逻辑 三层循环
for (MenuVO menu : menuVOList) { for (MenuVO menu : menuVOList) {
if (menuMap.containsKey(menu.getParentMenuCode())) { if (menuMap.containsKey(menu.getParentMenuCode())) {
if (menuMap.get(menu.getParentMenuCode()).getChildren() == null) { if (menuMap.get(menu.getParentMenuCode()).getChildren() == null) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment