// 列表页中返回json数据 @RequestMapping("/jsonList") public Object jsonList(HttpServletRequest request, HttpServletResponse response) { int currentPage = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page")); if (currentPage <= 0) { currentPage = 1; } int pageSize = request.getParameter("rows") == null ? 10 : Integer.parseInt(request.getParameter("rows")); Map filter = getFilterMap(request); int currentResult = (currentPage - 1) * pageSize; PageInfo pageInfo = new PageInfo(); pageInfo.setShowCount(pageSize); pageInfo.setCurrentResult(currentResult); pageInfo.setFilter(filter); pageInfo.setSortField("id"); pageInfo.setOrder("asc"); List<BaseMer> baseMers = baseMerService.selectListPage(pageInfo); if (pageInfo.getTotalResult() > 0) { Json json = new Json(); json.add("total", pageInfo.getTotalResult()); for (BaseMer baseMer : baseMers) { Json json_a = new Json(); try { json_a.getObjectValue(baseMer, json_a); } catch (Exception e) { e.printStackTrace(); } json.add("rows", json_a); } response.setContentType("application/json;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter pw = null; try { pw = response.getWriter(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } pw.write(json.toString()); pw.flush(); } return null; }
// 获取列表信息 @RequestMapping("/jsonUserstatue") public Object jsonList(HttpServletRequest request, HttpServletResponse response) { // 分页 int pageSize = request.getParameter("limit") == null ? 10 : Integer.parseInt(request.getParameter("limit")); Map filter = getFilterMap(request); int currentResult = Integer.parseInt(request.getParameter("offset")); response.setContentType("application/json;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter pw = null; PageInfo pageInfo = new PageInfo(); pageInfo.setShowCount(pageSize); pageInfo.setCurrentResult(currentResult); pageInfo.setFilter(filter); pageInfo.setSortField("ID"); pageInfo.setOrder("asc"); pageInfo.setFilter(filter); Long ID = null; if (request.getParameter("search_ID") != null && request.getParameter("search_ID") != "") { ID = Long.valueOf(request.getParameter("search_ID")); } filter.remove("ID"); List<T_USERSTATUEINFO> t_userstatueinfos = t_userstatueinfoService.selectListPage(pageInfo, ID); Json json = new Json(); if (t_userstatueinfos.size() == 0) { Json json_a = new Json(); json.add("total", 0); json.add("rows", json_a); try { pw = response.getWriter(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } pw.write(json.toString()); pw.flush(); return null; } json.add("total", pageInfo.getTotalResult()); for (T_USERSTATUEINFO t_userstatueinfo : t_userstatueinfos) { Json json_a = new Json(); json_a.add("state", ""); json_a.add("ID", String.valueOf(t_userstatueinfo.getId())); json_a.add( "STATUENAME", t_userstatueinfo.getStatueName() == null ? "" : t_userstatueinfo.getStatueName()); json_a.add( "STATUE", String.valueOf(t_userstatueinfo.getStatue()) == null ? "" : String.valueOf(t_userstatueinfo.getStatue())); json.add("rows", json_a); } try { pw = response.getWriter(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } pw.write(json.toString()); pw.flush(); return null; }
// 返回生成树需要的json @RequestMapping("/baseMerJsonTree") public Object baseMerJsonTree(HttpServletRequest request, HttpServletResponse response) { Map filter = getFilterMap(request); PageInfo pageInfo = new PageInfo(); pageInfo.setShowCount(100); pageInfo.setCurrentResult(0); pageInfo.setFilter(filter); pageInfo.setSortField("id"); pageInfo.setOrder("asc"); List<BaseMer> baseMers = baseMerService.selectListPage(pageInfo); if (pageInfo.getTotalResult() > 0) { StringBuffer sbf = new StringBuffer("["); Json json = new Json(); json.add("id", 1); json.add("text", "基质"); Json person = new Json(); person.add("id", 11); person.add("text", "人源基质"); Json noPerson = new Json(); noPerson.add("id", 12); noPerson.add("text", "非人源基质"); for (BaseMer baseMer : baseMers) { if (baseMer.getSource().equals("人源基质")) { Json json_a = new Json(); json_a.add("id", String.valueOf(baseMer.getId())); json_a.add("text", baseMer.getType()); person.add("children", json_a); } else { Json json_b = new Json(); json_b.add("id", String.valueOf(baseMer.getId())); json_b.add("text", baseMer.getType()); noPerson.add("children", json_b); } } json.add("children", person); json.add("children", noPerson); sbf.append(json.toString()); sbf.append("]"); response.setContentType("application/json;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter pw = null; try { pw = response.getWriter(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } pw.write(sbf.toString()); pw.flush(); } return null; }
// 列表页中返回json数据 @RequestMapping("/jsonList") public Object jsonList(HttpServletRequest request, HttpServletResponse response) { int pageSize = request.getParameter("limit") == null ? 10 : Integer.parseInt(request.getParameter("limit")); Map filter = getFilterMap(request); int currentResult = Integer.parseInt(request.getParameter("offset")); PageInfo pageInfo = new PageInfo(); pageInfo.setShowCount(pageSize); pageInfo.setCurrentResult(currentResult); pageInfo.setFilter(filter); pageInfo.setSortField("id"); pageInfo.setOrder("asc"); List<ControlNumInfo> controlNumInfos = controlNumInfoService.selectListPage(pageInfo); Json json = new Json(); if (pageInfo.getTotalResult() > 0) { json.add("total", pageInfo.getTotalResult()); for (ControlNumInfo controlNumInfo : controlNumInfos) { Json json_a = new Json(); json_a.add("id", String.valueOf(controlNumInfo.getId())); json_a.add("lotnum", controlNumInfo.getLotnum()); json_a.add("producetime", Kalendar.getFormat(controlNumInfo.getProducetime())); json_a.add("exp", Kalendar.getFormat(controlNumInfo.getExp())); json_a.add("vender", controlNumInfo.getVender()); json_a.add("expkf", String.valueOf(controlNumInfo.getExpkf())); json_a.add("foundtime", Kalendar.getFormat(controlNumInfo.getFoundtime())); json_a.add("description", controlNumInfo.getDescription()); json_a.add("foundman", controlNumInfo.getFoundman()); json_a.add("controlbaseid", String.valueOf(controlNumInfo.getControlbaseid().getId())); json_a.add("controlbasename", controlNumInfo.getControlbaseid().getControlmername()); json.add("rows", json_a); } } else { Json json_a = new Json(); json.add("total", 0); json.add("rows", json_a); } response.setContentType("application/json;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter pw = null; try { pw = response.getWriter(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } pw.write(json.toString()); pw.flush(); return null; }