商品分类
传递商品分类的父id值,获取属于这个父id的所有分类信息
CategoryController:
CategoryDTO:实体类TbCategory的数据传输对象
根据pid查询返回的是一个集合ResponseEntity<List<>>
ResponseEntity.ok= 200 ; 查询成功时返回时的状态码为200
//根据pid 查询分类信息集合
@RestController
@RequestMapping("/category")
public class CategoryController {
@Autowired
private TbCategoryService categoryService;
@GetMapping("/of/parent")
public ResponseEntity<List<CategoryDTO>> findCategoryByParentId(@RequestParam(name = "pid")Long parentId){
return ResponseEntity.ok(categoryService.findCategoryByParentId(parentId));
}
}
TbCategoryService:接口
/**
* <p>
* 商品类目表,类目和商品(spu)是一对多关系,类目与品牌是多对多关系 服务类
* </p>
*
* @author HM
* @since 2020-01-07
*/
public interface TbCategoryService extends IService<TbCategory> {
List<CategoryDTO> findCategoryByParentId(Long parentId);
}
TbCategoryServiceImpl:实现类
bean的拷贝 BeanHelper.copyProperties() , BeanHelper.copyWithCollection
前提:属性的名字相同才会拷贝。
/**
* <p>
* 商品类目表,类目和商品(spu)是一对多关系,类目与品牌是多对多关系 服务实现类
* </p>
*
* @author HM
* @since 2020-01-07
*/
@Service
public class TbCategoryServiceImpl extends ServiceImpl<TbCategoryMapper, TbCategory> implements TbCategoryService {
/*根据parentId查询category集合*/
@Override
public List<CategoryDTO> findCategoryByParentId(Long parentId) {
/*查询条件的对象*/
QueryWrapper<TbCategory> queryWrapper = new QueryWrapper<>();
/*select * from tb_category where parent_id = ? */
queryWrapper.eq("parent_id",parentId);
/*查询集合 this 内置方法*/
List<<