Java List<对象>转List<Map>

Java List<对象>转List

List<ApiBase> apiBaseList = apiBaseMapper.selectAll();

List<Map> apiMapList = apiBaseList.stream().map(it -> {
         Map<String, Object> apiMap = new HashMap<>();
         apiMap.put("id",it.getId());
         apiMap.put("name",it.getName());
         return apiMap;
 }).collect(Collectors.toList());

list 转list<对象>

class User{
    Long id;
    String userName;
    String password;
    String order;
    String name;
}
List<Map<String, Object>> listMap = new HashMap<>(10);

JSONArray jsonArray = new JSONArray();
jsonArray.addAll(listMap);
List<User> list = jsonArray.toJavaList(User.class);

你可能感兴趣的:(java,java)