-- 无限级菜单查询
SELECT A.MENU_ID, --菜单ID
LEVEL AS NODES, --菜单节点
A.MENU_NAME, --菜单名称
A.MENU_PAREDNT_ID,--菜单父ID
A.MENU_URL, --菜单url
A.ORDER_NO --排序号
FROM (SELECT B.MENU_ID,
B.MENU_NAME,
B.MENU_PAREDNT_ID,
B.MENU_URL,
B.ORDER_NO
FROM MENU B
WHERE 1 = 1) A
CONNECT BY A.MENU_PAREDNT_ID = PRIOR A.MENU_ID
START WITH A.MENU_PAREDNT_ID IS NULL
List returnList = "" // 这个list是通过SQL查询出来的结果集
List oneList = new ArrayList(); // 一级菜单List
Map twoMap = new HashMap(); // 二级菜单MAP
Map threeMap = new HashMap(); // 三级菜单MAP
// 封装成一个三级菜单的集合MAP
for (Object object : returnList) {
LazyDynaBean bean = (LazyDynaBean)object;
if ("1".equals(ObjectUtils.toString(bean.get("NODES")))){ // 判断该节点是否一级菜单
oneList.add(bean.getMap());
} else if ("2".equals(ObjectUtils.toString(bean.get("NODES")))) { // 判断该节点是否二级菜单
List tempList = (List)twoMap.get(ObjectUtils.toString(bean.get("MENU_PAREDNT_ID")));
if(tempList == null){
tempList = new ArrayList();
}
tempList.add(bean.getMap());
twoMap.put(ObjectUtils.toString(bean.get("MENU_PAREDNT_ID")), tempList);
} else if ("3".equals(ObjectUtils.toString(bean.get("NODES")))) {// 判断该节点是否三级菜单
List tempList = (List)threeMap.get(ObjectUtils.toString(bean.get("MENU_PAREDNT_ID")));
if(tempList == null){
tempList = new ArrayList();
}
tempList.add(bean.getMap());
threeMap.put(ObjectUtils.toString(bean.get("MENU_PAREDNT_ID")), tempList);
}
}
// 解析封装的数据
for(Object object : oneList) { // 一级菜单
Map oneMapNodes = (Map)object;
List twoListNodes = (List)twoMap.get(oneMapNodes.get("MENU_ID"));
if (twoListNodes!=null && twoListNodes.size()>0) {
for (Object twoobject : twoListNodes) { // 二级菜单
Map twoMapNodes= (Map)twoobject;
}
}
}
SELECT A.MENU_ID, --菜单ID
LEVEL AS NODES, --菜单节点
A.MENU_NAME, --菜单名称
A.MENU_PAREDNT_ID,--菜单父ID
A.MENU_URL, --菜单url
A.ORDER_NO --排序号
FROM (SELECT B.MENU_ID,
B.MENU_NAME,
B.MENU_PAREDNT_ID,
B.MENU_URL,
B.ORDER_NO
FROM MENU B
WHERE 1 = 1) A
CONNECT BY A.MENU_PAREDNT_ID = PRIOR A.MENU_ID
START WITH A.MENU_PAREDNT_ID IS NULL
List returnList = "" // 这个list是通过SQL查询出来的结果集
List oneList = new ArrayList(); // 一级菜单List
Map twoMap = new HashMap(); // 二级菜单MAP
Map threeMap = new HashMap(); // 三级菜单MAP
// 封装成一个三级菜单的集合MAP
for (Object object : returnList) {
LazyDynaBean bean = (LazyDynaBean)object;
if ("1".equals(ObjectUtils.toString(bean.get("NODES")))){ // 判断该节点是否一级菜单
oneList.add(bean.getMap());
} else if ("2".equals(ObjectUtils.toString(bean.get("NODES")))) { // 判断该节点是否二级菜单
List tempList = (List)twoMap.get(ObjectUtils.toString(bean.get("MENU_PAREDNT_ID")));
if(tempList == null){
tempList = new ArrayList();
}
tempList.add(bean.getMap());
twoMap.put(ObjectUtils.toString(bean.get("MENU_PAREDNT_ID")), tempList);
} else if ("3".equals(ObjectUtils.toString(bean.get("NODES")))) {// 判断该节点是否三级菜单
List tempList = (List)threeMap.get(ObjectUtils.toString(bean.get("MENU_PAREDNT_ID")));
if(tempList == null){
tempList = new ArrayList();
}
tempList.add(bean.getMap());
threeMap.put(ObjectUtils.toString(bean.get("MENU_PAREDNT_ID")), tempList);
}
}
// 解析封装的数据
for(Object object : oneList) { // 一级菜单
Map oneMapNodes = (Map)object;
List twoListNodes = (List)twoMap.get(oneMapNodes.get("MENU_ID"));
if (twoListNodes!=null && twoListNodes.size()>0) {
for (Object twoobject : twoListNodes) { // 二级菜单
Map twoMapNodes= (Map)twoobject;
}
}
}