java实体entity<----->map互转

 

一:entity转map

一句搞定,直接返回map对象:
import org.springframework.cglib.beans.BeanMap;


BeanMap.create(entityObj);

也可用jackson的ObjectMapper

 

二:map转实体类

        Map<String,String> map = new LinkedHashMap<>();
        ObjectMapper objectMapper = new ObjectMapper();
        User user = objectMapper.convertValue(map, User.class);

 posted on 2020-06-03 15:50  wu小强  阅读(4944)  评论(0编辑  收藏  举报