✅P84_新增商品-获取分类关联品牌
小于 1 分钟
接口信息
接口地址
GET:/product/categorybrandrelation/brands/list
CategoryBrandRelationController.java
请求参数
参数名 | 类型 | 描述 | 必填 |
---|---|---|---|
catId | long | 分类id | 必填 |
响应数据
{
"msg": "success",
"code": 0,
"data": [{
"brandId": 0,
"brandName": "string",
}]
}
后端代码
Controller
cfmall-product/src/main/java/com/gyz/cfmall/product/controller/CategoryBrandRelationController.java
@Autowired
private CategoryBrandRelationService categoryBrandRelationService;
@GetMapping(value = "/brands/list")
public R relationBransList(@RequestParam(value = "catId",required = true) Long catId) {
List<BrandEntity> vos = categoryBrandRelationService.getBrandsByCatId(catId);
List<BrandVo> collect = vos.stream().map(item -> {
BrandVo brandVo = new BrandVo();
brandVo.setBrandId(item.getBrandId());
brandVo.setBrandName(item.getName());
return brandVo;
}).collect(Collectors.toList());
return R.ok().put("data",collect);
}
Service
cfmall-product/src/main/java/com/gyz/cfmall/product/service/CategoryBrandRelationService.java
List<BrandEntity> getBrandsByCatId(Long catId);
cfmall-product/src/main/java/com/gyz/cfmall/product/service/impl/CategoryBrandRelationServiceImpl.java
@Autowired
private CategoryBrandRelationDao relationDao;
@Override
public List<BrandEntity> getBrandsByCatId(Long catId) {
List<CategoryBrandRelationEntity> catelogId = relationDao.selectList(new QueryWrapper<CategoryBrandRelationEntity>().eq("catelog_id", catId));
List<BrandEntity> collect = catelogId.stream().map(item -> {
Long brandId = item.getBrandId();
//查询品牌的详情
BrandEntity byId = brandService.getById(brandId);
return byId;
}).collect(Collectors.toList());
return collect;
}
测试
GET:http://localhost:8200/product/categorybrandrelation/brands/list