乐优商城商品分类,分页查询,新增品牌

乐优商城商品分类,分页查询,新增品牌

商品分类

传递商品分类的父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<<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值