/** * 递归函数加载子菜单 * * @param menuBean * @param menuList */ private void getMenuChildren(MenuBean menuBean, List<IMenu> menuList, Mapper mapper) { if (menuList == null || menuList.isEmpty()) return; List<MenuBean> childMenuList = new ArrayList<>(); for (IMenu menu : menuList) { if (menu.getParentMenuId() != null && menu.getParentMenuId().equals(menuBean.getId())) { MenuBean mBean = mapper.map(menu, MenuBean.class); mBean.setText(menu.getText()); childMenuList.add(mBean); getMenuChildren(mBean, menuList, mapper); } } menuBean.setChildren(childMenuList); }
/** * 获得菜单根节点 * * @param menuList * @return */ private IMenu getRootMenu(List<IMenu> menuList) { if (menuList == null || menuList.isEmpty()) return null; for (IMenu menu : menuList) { if (menu.getParentMenuId() == null) { return menu; } } return null; }
/** * 获得菜单根节点 * * @param menuList * @return */ private List<IMenu> getRootMenus(List<IMenu> menuList) { List<IMenu> rootMenus = new ArrayList<IMenu>(); if (menuList == null || menuList.isEmpty()) return rootMenus; for (IMenu menu : menuList) { if (menu.getParentMenuId() == null) { rootMenus.add(menu); } } return rootMenus; }