1、sql聚合函数,将查询到的一列值拼接到一个字段
GROUP_CONCAT( rep.`wg_name` SEPARATOR ',' )
2、java8将list中以特定符号隔开
String result5 = listCust.stream().map(String::valueOf).collect(Collectors.joining(","));
3、获取某一项元素组成新的list
List<String> res = list.stream() // 将列表转换为Stream
.map(WmsTblbarcodeScaned::getTblBarcode) // 提取每个人的名字
.collect(Collectors.toList()); // 收集结果到新的列表
```
- // 使用Stream API遍历List,并检查每个对象的某个属性是否为null
List<MyObject> objectsWithNullProperty = myList.stream()
.filter(obj -> obj.getProperty() == null)
.collect(Collectors.toList());
- // 使用Stream根据指定字段分组后求和
Map<String, Integer> listSignMap = signList.stream()
.collect(Collectors.groupingBy(
WmsSignApplication::getCInvCode,
Collectors.summingInt(WmsSignApplication::getQty)
));
- // 使用Stream API进行双层分组
Map<String, Map<String, List<ErpSyncOutDTO>>> res = erpSyncOutDTOS.stream()
.collect(Collectors.groupingBy(
ErpSyncOutDTO::getCCode,
Collectors.groupingBy(ErpSyncOutDTO::getSyncCode)
));
- // 根据元素过滤得到新的list
List<UpdateWmsStockInDTO> scannedExist = tblBarcodeList.stream()
.filter(dto -> !tblBarCodeStatusAll.contains(dto.getTblBarcode()))
.collect(Collectors.toList());