@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. 响应式设计的5个CSS实用技巧

    正如我在教程响应式Web设计三步走当中所讲的,响应式的Web设计其实并不难,但是要让元素在布局切换时能够平滑过渡就比较考验技巧了.现在我分享在编码时常用的五个CSS技巧并举例说明.这些技巧都是使用简单 ...

  2. Android 常用系统控件

    1. 日期选择器 DatePickerDialog 2. 时间选择器 TimePickerDialog 3. 单选按钮 RadioButton 4. 多选按钮 CheckBox 5. 下拉列表 Spi ...

  3. [walkthrough] 在Asp.net MVC6 RC里使用NLog,并且把配置集成到config.json

    说明一下:本文基于随visual studio 2015 RC公开的DNX1.0.0-beta4,git上最新的aspnet的开发版本已经发生了很大变化. 首先,理论部分看[汤姆大叔的博客] 解读AS ...

  4. MSSQL中datetime与unix时间戳互转

    //ms sql datetime 转unix时间戳 SELECT DATEDIFF(s, '19700101',GETDATE()) //ms sql unix时间戳 转datetime 涉及到时区 ...

  5. pycharm console 控制台乱码的解决

  6. JSP - request - 1

    <%@ page language="java" contentType="text/html;charset=utf8" %> <%@ pa ...

  7. cut 命令

    今天看到cut拿来取参数也是很方便的. cut -d = -f 2 -d表示分隔符 -f参数是分隔符算第几个参数

  8. Jump

    hdu4862:http://acm.hdu.edu.cn/showproblem.php?pid=4862 题意:给你n*m的方格,每个方格中有一个数(0---9),然后你每次可以选择一个点开始,这 ...

  9. ios入门之c语言篇——基本函数——5——素数判断

    参数返回值解析: 参数: m:int,需要判断的值: 返回值: 0:非素数 1:素数 函数解析: 注意:函数没有对输入进行判断,请自己屏蔽非法输入 int prime(int m) { int tem ...

  10. HDU 2553 N皇后问题(详细题解)

    这是一道深搜题目!问题的关键是在剪枝. 下面我们对问题进行分析: 1.一行只能放一个皇后,所以我们一旦确定此处可以放皇后,那么该行就只能放一个皇后,下面的就不要再搜了. 2.每一列只能放一个皇后,所以 ...