Map转Object和List<Map> 转List Object

1、Map转Object

例:

import com.alibaba.fastjson.JSON;


HashMap map = new HashMap<>();
map.put("username","test");
map.put("password","test");

User user = JSON.parseObject(JSON.toJSONString(map), User.class);

2、List转List

例:

List listMap = new ArrayList<>();
// 生成listMap略

List listUser = new ArrayList<>();
listMap.forEach(map -> {
        User user = JSON.parseObject(JSON.toJSONString(map), User.class);
        listUse.add(user);
});

你可能感兴趣的:(服务端,Map,Object,Map转Object)