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);
});
将一个list集合,按集合中的某个的字段拆分成若干个集合
于 2022-05-27 16:37:22 首次发布