递归

来源:互联网 发布:星际边界mac 编辑:程序博客网 时间:2024/05/21 08:48
private List<DutyDict> getChild(String id, List<DutyDict> rootMenu) {
// 子菜单
List<DutyDict> childList = new ArrayList<DutyDict>();
for (DutyDict menu : rootMenu) {
// 遍历所有节点,将父菜单id与传过来的id比较
if (!"0".equals(menu.getParentCode())) {
if (menu.getParentCode().equals(id)) {
childList.add(menu);
}
}
}
// 把子菜单的子菜单再循环一遍
for (DutyDict menu : childList) {// 没有url子菜单还有子菜单
// if (StringUtils.isBlank(menu.getUrl())) {
// 递归
menu.setChildMenus(getChild(menu.getShortCode(), rootMenu));
// }
} // 递归退出条件
if (childList.size() == 0) {
return null;
}
return childList;
}
原创粉丝点击