@RequestMapping(value = "/batchAddPageIndexBrand")
        @ResponseBody
        public HashMap<String, Object> batchAddPageIndexBrand(HttpServletRequest request,HttpServletResponse response){
            String userId = request.getSession().getAttribute("userId").toString();
            HashMap<String, Object> mapRes = new HashMap<String, Object>();
            List<PageIndexBrand> pageIndexBrandList=new ArrayList<PageIndexBrand>();
            String jsonStr=request.getParameter("json");
            if(StringUtils.isEmpty(jsonStr)){
                mapRes.put("code", -1);
                mapRes.put("msg","没有要操作的数据");
                return mapRes;
            }
         //将JSON字符串转为JSON数组 
            JSONArray json= JSONArray.fromObject(jsonStr);
            if(json==null || json.size()==0){
                mapRes.put("code", -1);
                mapRes.put("msg","没有要操作的数据");
                return mapRes;
            }
               //遍历JSON数组
            for(int i=0;i<json.size();i++){
              //获取JSON对象
                 JSONObject object = (JSONObject)json.get(i);
             //将JSON对象转为ModelBean
                 PageIndexBrand pageIndexBrand = (PageIndexBrand)JSONObject.toBean(object,PageIndexBrand.class);
                  if(pageIndexBrand != null){
                      pageIndexBrand.setAddUserId(Integer.parseInt(userId));
                      pageIndexBrand.setAddTime(StringUtil.returnDateFormat(new Date(),"yyyy-MM-dd HH:mm:ss"));
                      pageIndexBrand.setEditTime(StringUtil.returnDateFormat(new Date(),"yyyy-MM-dd HH:mm:ss"));
                      pageIndexBrand.setEditUserId(Integer.parseInt(userId));
                      pageIndexBrandList.add(pageIndexBrand);
                  }
            }
            ServiceMessage<?> res=pageIndexBrandService.batchOperateIndexBrand(pageIndexBrandList);
            if(res.getStatus().getCode().equals("0")){
                mapRes.put("code", 0);
                mapRes.put("msg", "ok");
            }else{
                mapRes.put("code", -1);
                mapRes.put("msg",res.getMessage());
            }
            return mapRes;
        }

JSON 遍历转为Model Bean的更多相关文章

  1. Json对象转为实体对象

    Json对象转为实体对象 1.Bean中申明 trainTypeList: public class TrainTypeQueryParam implements Serializable { pri ...

  2. php json字符串转为数组或对象

    从网上查到的方法是 用get_object_vars 把类类型转换成数组 然后在用foreach  遍历即可 $array = get_object_vars($test); $json= '[{&q ...

  3. json对象转为字符串,当做参数传递时加密解密

    [son对象  字符串 互相转行] 比如我有两个变量,我要将a转换成字符串,将b转换成JSON对象: var a={"name":"tom","sex ...

  4. SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法

    最近angularjs post到后台 400一头雾水 没有任何错误. 最后发现好文,感谢作者 SpringMVC中出现" 400 Bad Request "错误(用@Respon ...

  5. DataTable转json字符串,jQuery.parseJSON()把json字符串转为标准的json对象格式

    1.string res = DataTableToJson.DataTable2Json(dt);讲DataTable转换为json字符串 http://www.365mini.com/page/j ...

  6. 小程序json字符串转为对象

    小程序里json字符串转为对象使用JSON.parse()方法转变无效, 看报错提示有单引号“ ' ” 因为单引号而无效, 将单引号全改双引号即可. 报错如下: VM11050:1 thirdScri ...

  7. json遍历 分别使用【原】

    json遍历 一 使用org.json.JSONObject遍历 之后的所有遍历都参考了:http://blog.csdn.net/u010648555/article/details/4981538 ...

  8. 将JSON字典转换为Model文件

    将JSON字典转换为Model文件 1. 一切尽在不言中 2. 源码 https://github.com/YouXianMing/CreateModelFromJson 3. 说明 如果你还在手动写 ...

  9. 第61天:json遍历和封装运动框架(多个属性)

    一.json 遍历  for in  关键字  for ( 变量 in  对象)  { 执行语句;  } 例如: var json = {width:200,height:300,left:50}co ...

随机推荐

  1. Python自动化运维之27、Django(一)

    一.概述 1.什么是框架? 框架,即framework,特指为解决一个开放性问题而设计的具有一定约束性的支撑结构,使用框架可以帮你快速开发特定的系统,简单说就是使用别人搭好的舞台,你来做表演. 2.常 ...

  2. BZOJ 1033 杀蚂蚁

    Description 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试图把蛋糕搬回蚂蚁窝.而你的任 ...

  3. [BZOJ 1833] [ZJOI2010] count 数字计数 【数位DP】

    题目链接:BZOJ - 1833 题目分析 数位DP .. 用 f[i][j][k] 表示第 i 位是 j 的 i 位数共有多少个数码 k . 然后差分询问...Get()中注意一下,如果固定了第 i ...

  4. 静态与动态IP设置

    静态IP设置 netsh interface ipv4 set address name="本地连接" source=static addr=192.168.0.212 (这个地方 ...

  5. RR区间锁 不是唯一索引,即使区间内没值,也锁

    +--------- +---------------------------------------------------------------------------------------- ...

  6. Git skills in reseting files

    How to uncommit files that were committed long time a ago?Note: Since all changes in the current wor ...

  7. super返回不过来

    class Fruit {     String color = "未确定颜色";     //定义一个方法,该方法返回调用该方法的实例     public Fruit getT ...

  8. (转载)mysql 用drop和delete方法删除用户的区别

    (转载)http://hi.baidu.com/yymagento/item/56c3f6184bce8347e75e06db 在学习drop方法删除用户时,按照书上讲的一直没操作成功,后来到网上查了 ...

  9. 【最小生成树】Codeforces 707B Bakery

    题目链接: http://codeforces.com/problemset/problem/707/B 题目大意: 给你N个点M条无向边,其中有K个面粉站,现在一个人要在不是面粉站的点上开店,问到面 ...

  10. Matlab计算机视觉/图像处理工具箱推荐

    Matlab计算机视觉/图像处理工具箱推荐 转载http://cvnote.info/matlab-cv-ip-toolbox/ 计算机视觉/图像处理研究中经常要用到Matlab,虽然其自带了图像处理 ...