Stream流常用操作
1.根据某个字段进行去重
// 根据name去重
List<Community> unique = list.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Community::getName))), ArrayList::new)
);
2.把List中的所有实体类转换成Dto
//转换成dto列表
List<BarBarcodeInventoryDto> dtoList = barBarcodeInventoryList.stream().
map(barBarcodeInventory -> {
BarBarcodeInventoryDto dto = new BarBarcodeInventoryDto();
BeanUtils.copyProperties(barBarcodeInventory, dto);
return dto;
}).collect(Collectors.toList());