hutool依赖:BeanUtil工具类的使用:对象转对象、对象转map、map转对象

时间:2024-11-07 08:31:29
   <!--hutool-->
        <dependency>
            <groupId></groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.7.17</version>
        </dependency>

1.将User对象(多)转为UserDTO对象(少)

UserDTO userDTO = (user, );

数据转为UserDTO

UserDTO userDTO = (userMap, new UserDTO(), false);

3.将bean转为Map

 Map<String, Object> userMap = (userDTO, new HashMap<>());

4.将对象转为json

 ().set(key, (redisData));

5.将json转为对象

   String json = ().get(key);
    return (json, type);