获取List集合中特定的值

       //获取从js接收到的信息data

          String data = request.getParameter("data");
       //将data通过JsonUtil.jsonToBean转化为具体的实体类对象

        if (StringUtils.isNotBlank(data)) {
            courseVideoDTO = (CourseVideoDTO) JsonUtil.jsonToBean(data, CourseVideoDTO.class);
        }
       //创建一个List
         List<DefCodeInfoResDto> result = defCodeService.queryCodeInfo("special");
     

          //将List转换成字符串打印到控制台  System.out.println("List集合中的内容"+JSON.toJSONString(result));
         //具体内容为: [{"code":"1","code_type":"special","value":"培训"},{"code":"2","code_type":"special","value":"新人"},                                  {"code":"3","code_type":"special","value":"衔接"}]
       

              if(result.size()!=0){             //判断是否为空
              for (int i = 0; i < result.size(); i++) {              //for循环将数据逐一获取到
                DefCodeInfoResDto defCodeInfoResDto     =    result.get(i);
                String Code = defCodeInfoResDto.getCode();       //获取到的code值   1,2,3
                String Value = defCodeInfoResDto.getValue();      //获取到的value值    "培训","新人","衔接"
            }
        }


版权声明:本文为cxfjava原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。