ResultEntity

就是封装的一个map集合  省时省力好用

package com.ujy.utils;

import java.util.HashMap;
import java.util.Map;

public class ResultEntity {
    private Map<String,Object> map = new HashMap<String,Object>();

    public static ResultEntity success(){
        //相当于调用下面的map 然后把值存map里面 。
        ResultEntity entity = new ResultEntity();
        entity.getMap().put("statusCode",200);
        entity.getMap().put("message","发送成功");
        return entity;
    }
    //用来存值,对象,集合
    public  ResultEntity put (String key,Object value){
        this.getMap().put(key,value);
        return  this;
    }
    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

}

  当后面传过来的是map集合时 ,前端遍历形式:

       success:function (result) {
       //遍历map     key 是取出来的每个键,
        for (key in result.map.hashMap) {
         例子下面  把键放入到names 的这个数组中, 值放入sellCount这个数组中。
names.push(key); sellCount.push(result.map.hashMap[key]); }

后端传入形式

    //各个手机操作系统的使用情况分析
    @RequestMapping(value = "/phone",method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity getEchartData(){
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("IOS", 1600);
        map.put("Android", 3000);
        map.put("Sambian", 1000);
        map.put("windows", 2000);

        return ResultEntity.success().put("hashMap", map);
    }

 

  return ResultEntity.success().put("notice",notice);

 

 

posted @ 2019-12-06 00:44  呆code  阅读(1333)  评论(0编辑  收藏  举报