private void loadCategoryAndBrandName(List<Spu> list) {
for (Spu spu:list) {
//处理分类
List<String> names = categoryService.queryByIds(Arrays.asList(spu.getCid1(),
spu.getCid2(), spu.getCid3()))
.stream().map(d -> d.getName()).collect(Collectors.toList());
spu.setCname(StringUtils.join(names,"/"));
//处理品牌
spu.setBname(brandService.queryById(spu.getBrandId()).getName());
}
}
Arrays.asList(c1,c2,c3);把c1,c2,c3变为数组
.stream().map()把一个对象变为另一个对象
d-d.getName() list中的对象,取出名字
.collect(Collectors.toList());变为了一个名字的集合names
StringUtils.join(names,"/")把名字的集合,变为一个string类型,其中用“/”隔开