天天看點

兩個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之間的轉換。