天天看点

两个List实体类不同之间的直接转换

直接上代码,希望有java基础的童鞋能直接看懂实操。

//去数据库查询字典数据列表
List<Dict> dicts = myBaseInfoBiz.getChildDictListByCode(Code);
List<Dto> result = new ArrayList<>();
//直接把数据字典的内容,封装到一个map里面
if (CollectionUtil.isNotEmpty(dicts)) {
    result = dicts.stream().map(dict -> {
        Dto dto = Dtos.newDto();
        dto.put("appCode", dict.getType());
        dto.put("appName", dict.getTitle());
        return dto;
    }).collect(Collectors.toList());
}      

这是很省内存的一种两个list之间的转换。