public String execute() throws Exception { response.setCharacterEncoding("UTF-8"); int count = sysRightsService.findAllCount(); sysRightsList = sysRightsService.finsSysRightsByPage(page, rows); try { JSONObject json = new JSONObject(); JSONArray jsonItems = new JSONArray(); List list = sysRightsService.findSysRightsListByPaentId(0); // 父板块为0的子版快号 Iterator it = list.iterator(); while (it.hasNext()) { SysRights sysRights = (SysRights) it.next(); Map map = new HashMap(); map.put("sysRightsId", sysRights.getSysRightsId()); map.put("sysRightsName", sysRights.getSysRightsName()); map.put("className", sysRights.getClassName()); map.put("type", sysRights.getType()); map.put("status", sysRights.getStatus()); List sonList = sysRightsService.findSysRightsListByPaentId(sysRights.getSysRightsId()); // 获得编号 Iterator it2 = sonList.iterator(); JSONObject sonJson = new JSONObject(); JSONArray sonJsonItem = new JSONArray(); while (it2.hasNext()) { SysRights sysRights2 = (SysRights) it2.next(); Map map2 = new HashMap(); map2.put("sysRightsId", sysRights2.getSysRightsId()); map2.put("sysRightsName", sysRights2.getSysRightsName()); map2.put("className", sysRights2.getClassName()); map2.put("type", sysRights2.getType()); map2.put("status", sysRights2.getStatus()); sonJsonItem.add(map); } map.put("children", sonJsonItem); jsonItems.add(map); } json.put("total", count); json.put("rows", jsonItems); PrintWriter out = response.getWriter(); out.write(json.toString()); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); } return null; }