一、使用场景
把一个map转换成json字符串后存放在Redis中,然后在redis中取出json字符串,再把字符串转变成原来的Map
二、具体实现
1.1 Map转成String
这里使用是阿里巴巴fastjson
Map<String, Object> reportData = dssDashboardService.getReportData(yearMonth, DssDef.DssDashboardType.MONTH_INDEX.getCode());String jsonString = JSON.toJSONString(reportData);
1.2 String转成Map
Object object = redisTemplate.opsForValue().get(key);reportData = JSON.parseObject((String) object, Map.class);