• 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);
  • 相关阅读:
    python_workone
    python___"TypeError: 'module' object is not callable"
    显示pycharm的行号
    pycharm切换python版本
    yum安装pip
    informix数据库常用命令(转)
    eclipse打不开的解决办法
    linux修改时间大全
    在安装mysqli的时候,出现error: ext/mysqlnd/mysql_float_to_double.h: No such file or directory
    Amazon Linux AMI 2015.09 (HVM)平台搭建lamp
  • 原文地址:https://www.cnblogs.com/ych961107/p/11992961.html
Copyright © 2020-2023  润新知