<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.17</version>
</dependency>
1.将User对象(多)转为UserDTO对象(少)
UserDTO userDTO = BeanUtil.copyProperties(user, UserDTO.class);
hash(Map)数据转为UserDTO
UserDTO userDTO = BeanUtil.fillBeanWithMap(userMap, new UserDTO(), false);
3.将bean转为Map
Map<String, Object> userMap = BeanUtil.beanToMap(userDTO, new HashMap<>());
4.将对象转为json
stringRedisTemplate.opsForValue().set(key, JSONUtil.toJsonStr(redisData));
5.将json转为对象
String json = stringRedisTemplate.opsForValue().get(key);
return JSONUtil.toBean(json, type);
转载:hutool依赖:BeanUtil工具类的使用:对象转对象、对象转map、map转对象