Stream流的应用
Collectors.groupingBy(ShopCartItemDto::getShopId)

stream()
方法将该列表转化为一个流,可以对其中的元素进行操作。
collect()
方法是一个终止操作,用于将流的元素收集到一个集合中。在这里,groupingBy()
是Collectors
类的一个静态方法,它接受一个分类函数作为参数,并根据该函数对流中的元素进行分组 。
ShopCartItemDto::getShopId
是一个方法引用,指定了分类函数,即根据ShopCartItemDto对象的getShopId()
方法的返回值进行分组。
Collectors.groupingBy(ShopCartItemDto::getShopId) 是一个分组 的操作
其意思为通过shopId把shopCarItems中的每一个shopCarItemDto进行分类 形成一个Map集合
集合的键就是shopId 值就是shopCarItemDto
.filter(shopCartItemDto -> basketId.contains(shopCartItemDto.getBasketId()))

这里的shopCarItemDto 意思是取出dbShopCarItems中的每一个元素 名字可以是abcd 自己定义
filter是一个过滤器 用来筛选全部shopCarItemDto 中被basketId包含的元素