fastjson实现list转string转list

 public List listCityInfo(String provinceCode) {
        List cityInfoList;
        if(!redis.hexists(CacheConstants.CITY_KEY, provinceCode)) {
            Map param = new HashMap<>();
            param.put("eqProvinceCode", provinceCode);
            cityInfoList = cityInfoDAO.selectByMap(param);
            //list转换String
            String cityArray = JSONArray.toJSONString(cityInfoList);
            redis.hset(CacheConstants.CITY_KEY, provinceCode, cityArray);
            redis.expire(CacheConstants.CITY_KEY, CacheConstants.CACHE_EXPIRES_WEEK);
        } else {
            String cityArray = redis.hget(CacheConstants.CITY_KEY, provinceCode);
            //String转list
            cityInfoList = JSONArray.parseArray(cityArray, CityInfo.class);
        }
        return cityInfoList;
    }

你可能感兴趣的:(fastjson实现list转string转list)