问题:
将list以String格式存入Redis
stringRedisTemplate.opsForValue().set(key,JSONUtil.toJsonStr(list));
redis中存入的列表数据:会以JSONArray格式存储
[
{
"icon": "/types/ms.png",
"updateTime": 1640229871000,
"sort": 1,
"createTime": 1640175467000,
"name": "美食",
"id": 1
}
]
取数据
String shoplistJson = stringRedisTemplate.opsForValue().get(key);
//需要把string转为数组
JSONArray jsonArray = JSONUtil.parseArray(shoplistJson);
//解析数组,并转为list
List<ShopType> list = JSONUtil.toList(JSONUtil.parseArray(shoplistJson), ShopType.class);