继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

很给力的后台管理系统动态菜单的实现方法

爱总结的小仙女
关注TA
已关注
手记 47
粉丝 57
获赞 437
//获取左面菜单表的二级菜单
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,阅读手记
2人推荐
发表评论
随时随地看视频慕课网APP