一、使用场景
1、当必要对一个list中的元素属性进行重新赋值,比如一个list中存储了订单数据,我们必要改变list中每个订单的id,然后再重新输出订单list
if(CollectionUtils.isNotEmpty(orderList)){
orderList.forEach(p->{
PointsExchangeOrderItem item = new PointsExchangeOrderItem();
item.setOrderId(p.getId());
List<ointsExchangeOrderItem> itemList = item.select();
if (CollectionUtils.isNotEmpty(itemList)){
List<String> collects = itemList.stream().map(PointsExchangeOrderItem::getExchangeId).collect(Collectors.toList());
String exchangeIdStr = String.join(",", collects);
p.setExchangeInPointsId(exchangeIdStr);
p.setExchangeOutPointsId(exchangeIdStr);
}
});
}
return orderList;
- if(CollectionUtils.isNotEmpty(orderList)){
- orderList.forEach(p->{
- PointsExchangeOrderItem item = new PointsExchangeOrderItem();
- item.setOrderId(p.getId());
- List<PointsExchangeOrderItem> itemList = item.select();
- if (CollectionUtils.isNotEmpty(itemList)){
- List<String> collects = itemList.stream().map(PointsExchangeOrderItem::getExchangeId).collect(Collectors.toList());
- String exchangeIdStr = String.join(",", collects);
- p.setExchangeInPointsId(exchangeIdStr);
- p.setExchangeOutPointsId(exchangeIdStr);
- }
- });
- }
- return orderList;
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |