Java List<对象>转List

2021-05-11  本文已影响0人  赵哥窟

某一个表的字段很多,表映射的对象已经有了。但是前端不需要那么字段。利用Mapper.selectAll()查询出来的结果,在取前端需要的字段重新组成一个Map返回就好了。

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());
上一篇 下一篇

猜你喜欢

热点阅读