前言
不同商家的商品,购物车统一结算按卖家拆单
将一个list集合,按集合中的某个的字段拆分成若干个集合
List<ShopProductVo> shopProductVos = new ArrayList<>();
for (ShopCart shopCart : shopCarts) {
//查找出购物车商品,放入集合
shopProductVos.add(shopStockSizeMapper.selectProductVoByS_id(shopCart.getsId()));
}
//将集合按卖家分单
List<List<ShopProductVo>> groupList = new ArrayList<>();
//java8:Collectors.groupingBy根据一个或多个属性对集合中的项目进行分组
shopProductVos.stream().collect(Collectors.groupingBy(ShopProductVo::getAccount_id, Collectors.toList()))
.forEach((accountId, shopProductVoList) -> {
groupList.add(shopProductVoList);
});