1.商品新增
1.1.controller
在BrandController中添加queryBrandByCid方法
/**
* 根据cid查询品牌
* @param cid
* @return
*/
@GetMapping("/cid/{cid}")
public ResponseEntity<List<Brand>> queryBrandByCid(@PathVariable("cid")Long cid){
return ResponseEntity.ok(brandService.queryBrandByCid(cid));
}
1.2.service
在BrandService中添加queryBrandByCid方法
public List queryBrandByCid(Long cid) {
List<Brand> list = brandMapper.queryByCategoryId(cid);
if (CollectionUtils.isEmpty(list)){
throw new LyException(ExceptionEnum.BRAND_NOT_FOUND);
}
return list;
}
1.3.mapper
在BrandMapper中添加queryByCategoryId方法
注意:这是两表关联查询
@Select("SELECT b.*\n" +
"FROM tb_brand b\n" +
"INNER JOIN tb_category_brand cb ON b.id = cb.brand_id\n" +
"WHERE cb.category_id = #{cid}")
List<Brand> queryByCategoryId(@Param("cid")Long cid);
1.4.测试
此小节结束:2020/5/6 18:47:54