/** * * 菜单权限 * * @return */ public String menuRoles() { List<Tree> list = roleService.findMenuRole(map); Map<Tree, List<Tree>> hashMap = new HashMap<Tree, List<Tree>>(); for (int i = 0; i < list.size(); i++) { if (list.get(i).getMenuHigherNo() == null || list.get(i).getMenuHigherNo().equals("")) { if (!hashMap.containsKey(list.get(i))) { List<Tree> arrayList = new ArrayList<Tree>(); hashMap.put(list.get(i), arrayList); } else { List<Tree> treeList = hashMap.get(list.get(i)); treeList.add(list.get(i)); hashMap.put(list.get(i), treeList); } } else { for (Iterator<Tree> x = hashMap.keySet().iterator(); x.hasNext(); ) { Tree tree = x.next(); if (list.get(i).getMenuHigherNo() != null && list.get(i).getMenuHigherNo().equals(tree.getMenuCode())) { List<Tree> treeList = hashMap.get(tree); treeList.add(list.get(i)); } { continue; } } } } String str = "["; for (Iterator<Tree> x = hashMap.keySet().iterator(); x.hasNext(); ) { Tree tree = x.next(); List<Tree> childTree = hashMap.get(tree); str += "{\"id\":\"" + "" + tree.getId() + "\",\"text\":\"" + tree.getText() + "\",\"children\":" + JSONArray.fromObject(childTree) + "}"; str += ","; } str = str.substring(0, str.length() - 1); str += "]"; HttpServletResponse response = ServletActionContext.getResponse(); try { PrintWriter out = response.getWriter(); out.print(str); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
public String findRoleList() { JSON json = JSONArray.fromObject(roleService.findRoleList(map)); HttpServletResponse response = ServletActionContext.getResponse(); try { PrintWriter out = response.getWriter(); out.print(json.toString()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
public String addRole() { role = new Role(); role.setMemo(map.get("memo")); role.setRoleName(map.get("roleName")); role.setRoleStatus("1"); // 1 表示正常 0表示不正常 int count = roleService.insert(role); HttpServletResponse response = ServletActionContext.getResponse(); try { PrintWriter out = response.getWriter(); out.print("success"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }