81,092
社区成员
发帖
与我相关
我的任务
分享
<%@ page language="java" pageEncoding="utf-8"%><%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %><ul class="nav navbar-nav nav-tables"><c:forEach var="menu" items="${menus}">
<li class="dropdown"><a href="<c:url value="${menu.menuUrl}" />" <c:if test="${fn:length(menu.childMenus) > 0}">data-toggle="dropdown"</c:if> <c:if test="${menu.menuUrl != '#'}">target="sys_content"</c:if>><c:out value="${menu.menuName}" /><c:if test="${fn:length(menu.childMenus) > 0}"><b class="caret"></b></c:if></a><c:if test="${fn:length(menu.childMenus) > 0}"><ul class="dropdown-menu"></c:if>
<c:forEach var="child" items="${menu.childMenus}"><li <c:if test="${fn:length(child.childMenus) > 0}">class="dropdown-submenu"</c:if>><a href="<c:url value="${child.menuUrl}" />" <c:if test="${fn:length(child.childMenus) > 0}">data-toggle="dropdown"</c:if> <c:if test="${child.menuUrl != '#'}">target="sys_content"</c:if>><c:out value="${child.menuName}" /></a><c:if test="${fn:length(child.childMenus) > 0}"><ul class="dropdown-menu"></c:if><c:forEach var="leaf" items="${child.childMenus}"><li><a href="<c:url value="${leaf.menuUrl}" />" target="sys_content"><c:out value="${leaf.menuName}" /></a></li></c:forEach>
<c:if test="${fn:length(child.childMenus) > 0}"></ul></c:if></li>
</c:forEach><c:if test="${fn:length(menu.childMenus) > 0}"></ul></c:if></li></c:forEach>
</ul>
@Override
public List<SysMenuBean> queryMenus() throws ServiceException {
try{
List<SysMenuBean> resultMenuList = new ArrayList<SysMenuBean>();
List<SysMenuBean> menuList = sysMenuDao.queryMenus();
for(SysMenuBean menu : menuList) {
String parentMenuId = menu.getParentMenuId();
if(StringUtils.isEmpty(parentMenuId)){
menu.setChildMenus(genMenu(menuList, menu.getMenuId()));
resultMenuList.add(menu);
}
}
return resultMenuList;
} catch(DaoException e) {
log.error("queryMenus", e);
throw new ServiceException(e);
}
}
/*
* 设置菜单
*/
private List<SysMenuBean> genMenu(List<SysMenuBean> menus, String parentMenuId){
List<SysMenuBean> list = new ArrayList<SysMenuBean>();
for(SysMenuBean menu: menus) {
String parentId = menu.getParentMenuId();
if(parentMenuId.equals(parentId)){
menu.setChildMenus(genMenu(menus, menu.getMenuId()));
list.add(menu);
}
}
return list;
}