数据格式转换

list转String

 List<ThirdZCountVo> thirdTimeList = thirdService.selectTimeList();
String st1=JSONArray.fromObject(thirdTimeList).toString()

String转list

  List<ThirdZCountVo> list = JSON.parseArray(st1, ThirdZCountVo.class);

redis 格式转换

 Jedis jedis = new Jedis("127.0.0.1", 6379);

        //先从缓存中查询
        List<ThirdZCountVo> str = JSON.parseArray(jedis.get("thirdZCountVoList"), ThirdZCountVo.class);
        if (str == null) {
            List<ThirdZCountVo> thirdZCountVoList = thirdService.selectZCount();
            jedis.set("thirdZCountVoList", JSONArray.fromObject(thirdZCountVoList).toString());

        }
        List<ThirdZCountVo> thirdZCountVoList = JSON.parseArray(jedis.get("thirdZCountVoList"), ThirdZCountVo.class);

把查询出的list 其中一列元素的值转为数组

 List<ThirdVo> thirdShipVo =  new ArrayList<>();
        //  获取数据 --数组对象 Long mss ,分割
        List<Long> mss = thirdShipVo.stream().map(ThirdVo::getMs).collect(Collectors.toList());
        //转数组 用,连接
        String join = StringUtils.join(mss, ",");

JSONObject 转对象

//JSONObject page
 JSONObject jsonObject = JSONObject.parseObject(String.valueOf(page));
        PageVo page2 = JSON.toJavaObject(jsonObject, PageVo.class);
上一篇:阻塞式发送邮件


下一篇:3.1 Jedis客户端之直连