递归封装层级菜单(java版)

递归封装层级菜单(java)

解决方法:

1.menuList就是递归后封装的层级菜单

//rootMenu所有菜单的集合

List<Map<Object, Object>> rootMenu = baseService.excuteQueryList(sql, null);

List<Map<Object, Object>> menuList = new ArrayList<Map<Object, Object>>();

// 先找到所有的一级菜单

for (int i = 0; i < rootMenu.size(); i++) {

// 一级菜单没有parentId

if ("0".equals(rootMenu.get(i).get("parentId").toString())) {

menuList.add(rootMenu.get(i));

}

}

// 为一级菜单设置子菜单,getChild是递归调用的

for (Map<Object, Object> menu : menuList) {

List<Map<Object, Object>> childs = getChild(menu.get("id").toString(), rootMenu);

if(childs!=null&&childs.size()>0){

menu.put("childs",childs);

}

}

2.递归查找子菜单方法:http://www.yayihouse.com/yayishuwu/chapter/1823

猜你喜欢

转载自blog.csdn.net/qq_30908729/article/details/88701847