集合转json json转集合
导包
xml
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
集合转json
java
import org.springframework.data.redis.core.StringRedisTemplate;
// 注入StringRedisTemplate
@Autowired
private StringRedisTemplate redisTemplate;
// 在某个方法里将
public void redisMenthod(){
// 拿到集合 ZtAuthResource是我的实体类
List<ZtAuthResource> list = list();
// 存入redis
redisTemplate.opsForValue().set("resourceList", JSON.toJSONString(list));
}
json转集合
java
// 引的包
import com.alibaba.fastjson.JSONArray;
List<ZtAuthResource> redisResourceList = JSONArray.parseArray(redisResourceListStr, ZtAuthResource.class);