menu 菜单层级关系MAP组装
来源:互联网 发布:wps数据有效性设置取消 编辑:程序博客网 时间:2024/06/06 23:16
1、map 赋值
2、层级关系map 转换
3、获取某一层级的关系
4、首层排序
5、二层排序 (有点冗余)
@ResponseBody@RequestMapping(value="subMenu", method = RequestMethod.POST)public Object submenu(String parent_id,Model model) {List<MenuNodeForm> subMenuList = new ArrayList<MenuNodeForm>();try {List<BaseMenu> subMenu = null;Map<String, MenuNodeForm> map = new HashMap<String, MenuNodeForm>();if(parent_id != null && !"".equals(parent_id)){subMenu = menuService.subMenu("0",this.getCurrentUser().roles);for (BaseMenu menu: subMenu) {if (menu.getId() != null && !"".equals(menu.getId())) {MenuNodeForm nodeForm = new MenuNodeForm();nodeForm.setId(menu.getId());nodeForm.setCaption(menu.getCaption());nodeForm.setMenu_type(menu.getMenu_type());nodeForm.setResource_url(menu.getResource_url());nodeForm.setParent_id(menu.getParent_id());nodeForm.setSort(menu.getSort());map.put(menu.getId(),nodeForm);}}for ( Entry<String, MenuNodeForm> entry : map.entrySet() ) {MenuNodeForm menuNodeForm = entry.getValue();String sParentId = menuNodeForm.getParent_id();MenuNodeForm nodeTree = map.get(sParentId);if ( nodeTree != null ) {nodeTree.getBaseMenu().add(menuNodeForm);}}Iterator<String> it = map.keySet().iterator();while (it.hasNext()) {String key = it.next().toString();if(map.get(key).getParent_id().equals(parent_id)){subMenuList.add(map.get(key));}}Collections.sort(subMenuList,new Comparator<MenuNodeForm>(){@Overridepublic int compare(MenuNodeForm arg0, MenuNodeForm arg1) {if(arg0.getSort() != null && arg1.getSort() != null){return arg0.getSort().compareTo(arg1.getSort());} else {return 0;}}});if(subMenuList != null && subMenuList.size() > 0){for(int i = 0; i < subMenuList.size(); i++){if(subMenuList.get(i).getBaseMenu() != null && subMenuList.get(i).getBaseMenu().size() > 0){Collections.sort(subMenuList.get(i).getBaseMenu(),new Comparator<MenuNodeForm>(){@Overridepublic int compare(MenuNodeForm arg0, MenuNodeForm arg1) {if(arg0.getSort() != null && arg1.getSort() != null){return arg0.getSort().compareTo(arg1.getSort());} else {return 0;}}});}}}System.out.println(JSONArray.fromObject(subMenuList));}} catch (SQLException e) {logger.error(e.getMessage());}return JSON.toJSON(subMenuList);}
0 0
- menu 菜单层级关系MAP组装
- 组装机主板boot menu
- 菜单(menu)
- Menu菜单
- 菜单 MENU
- 菜单(Menu)
- 菜单Menu
- Menu 菜单
- Menu 菜单
- Menu菜单
- menu(菜单)
- Menu菜单
- Menu菜单
- Menu菜单
- menu菜单
- Menu 菜单
- Menu菜单
- menu菜单
- 注册码系统防破解教程,如何防破解?
- 入门深度学习mxnet框架——运行mnist手写数字例子
- jquery 遍历
- Go 语言标准库之 strings包
- Android总结篇系列:Activity启动模式(lauchMode)
- menu 菜单层级关系MAP组装
- vimrc文件的配置
- LeetCode 12. Integer to Roman
- js闭包
- 机器人驱动介绍(2)
- 加载 Logo 动画 试玩
- mysql出现Connection.close() has already been called. Invalid operation in this state.
- 图像显示
- 关于伺服电机的控制方式