1. 程式人生 > >後端實現int類型改成相應的Sting字符串

後端實現int類型改成相應的Sting字符串

limit shm util setname add detach lis col 類型



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     }

後端實現int類型改成相應的Sting字符串