赞
踩
查询数据库所有菜单项
- @Override
- public List<IntraMenu> queryMenuListByUserCode(String userCode) {
- List<IntraMenu> menuList = new ArrayList<IntraMenu>();
- String sql = "select * from fpd.T_INTRA_MENU m where m.status=1 "
- + "and m.code in (select rm.menu_Code from fpd.T_INTRA_ROLE_MENU rm "
- + "where rm.role_code in (select ur.role_code from fpd.T_INTRA_USER_ROLE ur"
- + " where ur.USER_CODE= ? )) order by m.order_no desc";
- Object[] paramArr = new Object[]{userCode};
- List<Map<String, Object>> queryList = jdbcTemplate.queryForList(sql, paramArr);
- if (!CollectionUtils.isEmpty(queryList)) {
- for (Map<String, Object> map : queryList) {
- IntraMenu model = new IntraMenu();
- model.setId(((BigDecimal)map.get("ID")).longValue());
- model.setCode(map.get("CODE").toString());
- if(map.get("P_CODE")!=null){
- model.setpCode(map.get("P_CODE").toString());
- }
- model.setRankLevel(((BigDecimal)map.get("RANK_LEVEL")).intValue());
- model.setName(map.get("NAME").toString());
- if(map.get("URL")!=null){
- model.setURL(map.get("URL").toString());
- }
- model.setOrderNo(((BigDecimal)map.get("ORDER_NO")).intValue());
- menuList.add(model);
- }
- }
- return menuList;
- }
树形处理
- @RequestMapping(value = "/main")
- public ModelAndView loginSuccess(HttpServletRequest request, HttpServletResponse response) {
- String loginName = request.getParameter("loginName");
- ModelAndView mv = new ModelAndView("intra/login/main");
- String name = FPDUtils.getUserCode();
- mv.addObject("name", name);
- List<IntraMenu> menuList = intraBaseQueryService.queryMenuListByUserCode(loginName);
- List<IntraMenu> pMenuList = new ArrayList<IntraMenu>();
- MultiMap multiMap = new MultiHashMap();
- if(CollectionUtils.isNotEmpty(menuList)){
- for(IntraMenu menu:menuList){
- if(menu.getRankLevel()==2){
- String menuCode="",menuName="";
- menuCode = menu.getpCode();//找父节点
- //根据父节点编码找相应的名称
- IntraMenu pMenu = intraBaseQueryService.queryByMenuCode(menuCode);
- if(pMenu!=null){
- menuName = pMenu.getName();
- multiMap.put(menuCode+"@"+menuName, menu);
- }else{
- logger.error("父节点编码:"+menuCode+"不存在");
- }
- }else{
- menu.setCode(menu.getCode()+"@"+menu.getName());
- pMenuList.add(menu);
- }
- }
- }
- Set<String> keySet = multiMap.keySet();
- List<IntraTreeMenu> list = new ArrayList<IntraTreeMenu>();
-
- for(IntraMenu menu:pMenuList){
- for(Iterator<String> iterator =keySet.iterator();iterator.hasNext();){
- String mapKey = iterator.next();
- if(menu.getCode().equals(mapKey)){
- IntraTreeMenu intraTreeMenu = new IntraTreeMenu();
- List<IntraMenu> children = (List<IntraMenu>) multiMap.get(mapKey);
- intraTreeMenu.setCode(mapKey.split("@")[0]);
- intraTreeMenu.setName(mapKey.split("@")[1]);
- intraTreeMenu.setChildren(children);
- list.add(intraTreeMenu);
- }
- }
- }
-
- mv.addObject("menuList", list);
- return mv;
- }
前端处理
- <div class="accordionContent">
- <ul class="tree treeFolder">
- <#if menuList?exists&&(menuList?size>0)>
- <#list menuList as menu>
- <li>
- <a href="javascript:void(0);">${menu.name}</a>
- <ul>
- <#list menu.children as menuChild>
- <li><a target="navTab" external="true" rel="${menuChild.code}" href="${menuChild.URL}">${menuChild.name}</a></li>
- </#list>
- </ul>
- </li>
- </#list>
- </#if>
- </ul>
- </div>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。