后端实现int类型改成相应的Sting字符串

Posted 清雨染墨衣o

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了后端实现int类型改成相应的Sting字符串相关的知识,希望对你有一定的参考价值。



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字符串的主要内容,如果未能解决你的问题,请参考以下文章

c++字符串截取 编写函数如substr(sting s ,int n) 要求取字符串S 的第N个字符 如 substr(k123,3) 结果为2

对Sting类型的探讨

Char类型与Sting类型的数字字符转换时的不同点

string转化为int

如何将 int 映射到 C/C++ 中的相应字符串

在sql语句中怎样把char类型转换成int类型?