public List<Menu> listAllMenu() { List<Menu> rl = this.listAllParentMenu(); if (rl != null && rl.size() > 0) { for (Menu menu : rl) { List<Menu> subList = this.listSubMenuByParentId(menu.getMenuId()); menu.setSubMenu(subList); } } return rl; }
public void saveMenu(Menu menu) throws Exception { if (menu == null) { this.logger.warn("保存菜单失败:参数menu为空"); throw new Exception("保存菜单失败:参数menu为空"); } if (menu.getMenuId() != null && menu.getMenuId().intValue() > 0) { menuMapper.updateMenu(menu); } else { menuMapper.insertMenu(menu); } }
/** * 请求用户授权页面 * * @param userId * @param model * @return */ @RequestMapping(value = "/auth{userId}") public String auth(@PathVariable int userId, Model model) { List<Menu> menuList = menuService.listAllMenu(); User user = userService.getUserById(userId); String userRights = ""; if (user != null) { userRights = user.getRights(); } if (Tools.notEmpty(userRights) && menuList != null && menuList.size() > 0) { for (Menu menu : menuList) { menu.setHasMenu(RightsHelper.testRights(userRights, menu.getMenuId())); if (menu.isHasMenu()) { List<Menu> subRightsList = menu.getSubMenu(); for (Menu sub : subRightsList) { sub.setHasMenu(RightsHelper.testRights(userRights, sub.getMenuId())); } } } } JSONArray arr = JSONArray.fromObject(menuList); String json = arr.toString(); json = json.replaceAll("menuId", "id") .replaceAll("menuName", "name") .replaceAll("subMenu", "nodes") .replaceAll("hasMenu", "checked"); model.addAttribute("zTreeNodes", json); model.addAttribute("userId", userId); return "user/authorization"; }