//获取左面菜单表的二级菜单
public List<Map<String,Object>> QueryLeftCmenu(BigDecimal rid) {
//根据角色的rid查询出对应的菜单表的主mid
List<Map<String,Object>> ll=Querymid(rid);
//根据多个菜单的主mid,查询出它对应的菜单,使用的是自连接
String midStr = "";
for(int i=0;i<ll.size();i++){
if(i==ll.size()-1){
midStr = midStr + ll.get(i).get("MID").toString();
}else{
midStr = midStr + ll.get(i).get("MID").toString() + ",";
}
}
Session session=this.getSession();
String sql="select a.mid as zid,a.mname as zname,b.pid as cid,b.mname as cname,b.url from menu a,menu b where a.mid=b.pid and a.mid in ("+midStr+")";
Query query=session.createSQLQuery(sql);
query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
return query.list();
}
//获取左面菜单的一级菜单
public List<Map<String,Object>> QueryLeftZmenu(BigDecimal rid) {
List<Map<String,Object>> ll=Querymid(rid);
String midStr = "";
for(int i=0;i<ll.size();i++){
if(i==ll.size()-1){
midStr = midStr + ll.get(i).get("MID").toString();
}else{
midStr = midStr + ll.get(i).get("MID").toString() + ",";
}
}
Session session=this.getSession();
String sql="select distinct a.mid zid,a.mname zname from menu a,menu b where a.mid=b.pid and a.mid in ("+midStr+")";
Query query=session.createSQLQuery(sql);
query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
return query.list();
}
//页面显示如下
//Zlist是 调用QueryLeftZmenu()得出,CList调用QueryLeftCmenu()得出
<c:forEach items="${Zlist}" var="a">
<li>
<a href="#" class="dropdown-toggle">
<i class="icon-desktop"></i>
<span class="menu-text"> ${a.ZNAME} </span>
<b class="arrow icon-angle-down"></b>
</a>
<ul class="submenu">
<c:forEach items="${CList}" var="b">
<c:if test="${a.ZID==b.CID}">
<li>
<a href="<%=path%>/${b.URL}">
${b.CNAME}
</a>
</li>
</c:if>
</c:forEach>
</ul>
</li>
</c:forEach>
打开App,阅读手记