private void util_setName(JSONArray jsonArray){ // JSONObject stationJson = inspectionService.getStationIdName(); JSONObject json; for (int i = 0; i < jsonArray.length(); i++) { try { json = jsonArray.getJSONObject(i); // json.put("station",stationJson.optString(json.getString("station"),json.getString("station"))); json.put("priority",Task.priorityMap.get(json.getInt("priority"))); json.put("status",Task.statusMap.get(json.getInt("status"))); // json.put("source",Task.teamMap.get(json.getInt("team"))); } catch (JSONException e) { e.printStackTrace(); } } }
实体类里添加MAP
private Integer id; private String name; //项目名称 private String major; //专业 private String team; //班组 private String responsible; //责任人 private Date startTime;//开始时间 private Date dueDate; //计划完成时间 private Integer priority; //优先级 private String content ; //详细内容 private Date finishTime; //实际完成时间 private String gradeEstimation; //质量评定 private int status; //状态 public static final Map<Integer,String> priorityMap = new LinkedHashMap<Integer, String>(); public static final Map<Integer,String> majorMap = new LinkedHashMap<Integer, String>(); public static final Map<Integer,String> teamMap = new LinkedHashMap<Integer, String>(); public static final Map<Integer,String> statusMap = new LinkedHashMap<Integer, String>(); static{ //优先等级 priorityMap.put(0,"优先"); priorityMap.put(1,"一般"); //专业 majorMap.put(0,"环控"); majorMap.put(1,"动照"); majorMap.put(2,"给排水"); majorMap.put(3,"屏蔽门"); majorMap.put(4,"电梯"); //班组 teamMap.put(0,"机电一工班"); teamMap.put(1,"机电二工班"); teamMap.put(2,"机电三工班"); teamMap.put(3,"机电四工班"); teamMap.put(4,"门梯工班"); //状态 statusMap.put(0,"新建"); statusMap.put(1,"进行中"); statusMap.put(2,"已完成"); statusMap.put(3,"超时"); }
action层 14行代码
1 public JSONObject page(int start,int limit,String sortField,String sortOrder,String priority){ 2 DetachedCriteria criteria = dao.query( priority); 3 int total = dao.getRowCount(criteria); 4 criteria = dao.query(priority); 5 if(sortField!=null){ 6 if(sortOrder==null){ 7 sortOrder = "asc"; 8 } 9 criteria.add(Restrictions.sqlRestriction("1=1 order by "+sortField+" "+sortOrder)); 10 } 11 List<Task> list = dao.findByCriteria(criteria, start, limit); 12 JSONArray jsonArray = listsToJsonA(list); 13 util_setName(jsonArray); //放入对应的名字 14 return DataTable_BaseAction.getDataTableJson(total, total, jsonArray); 15 }