本文包含以下内容:
获取分类的品牌关系列表
新增商品第二步,根据属性获取所有的属性接口
新增商品第三步,编写sku 信息
根据提交json 生成实体类
1.获取分类的品牌关系列表
接上文,添加商品选择完分类,显示报错,查詢分类和品牌关系,的接口 404,找不到,所以添加新的接口 1) 添加控制层,接口,接收分类id/** * /product/categorybrandrelation/brands/list * * 1、Controller:处理请求,接受和校验数据 * 2、Service接受controller传来的数据,进行业务处理 * 3、Controller接受Service处理完的数据,封装页面指定的vo */@GetMapping("/brands/list")public R relationBrandsList(@RequestParam(value = "catId",required = true)Long catId){ List vos = categoryBrandRelationService.getBrandsByCatId(catId); List 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);}
2)添加
封装返回的Vo 层
package com.atguigu.gulimall.product.vo;import lombok.Data;@Datapublic class BrandVo { /** * "brandId": 0, * "brandName": "string", */ private Long brandId; private String brandName;}
3)添加Service 层进行
数据查詢,实现方法,处理返回
@Overridepublic List getBrandsByCatId(Long catId) { List catelogId = relationDao.selectList(new QueryWrapper().eq("catelog_id", catId)); List collect = catelogId.stream().map(item -> { Long brandId = item.getBrandId(); BrandEntity byId = brandService.getById(brandId); return byId; }).collect(Collectors.toList()); return collect;}
得到效果,可以查詢到指定分类下的品牌
2.新增商品第二步,根据属性获取所有的属性接口
进入添加商品第二步,查詢分类关联的属性分组,对应的规格参数,接口 404,尚未编写 1) 添加控制层,添加接口,从地址获取分类的id///product/attrgroup/{catelogId}/withattr@GetMapping("/{catelogId}/withattr")public R getAttrGroupWithAttrs(@PathVariable("catelogId")Long catelogId){ //1、查出当前分类下的所有属性分组, //2、查出每个属性分组的所有属性 List vos = attrGroupService.getAttrGroupWithAttrsByCatelogId(catelogId); return R.ok().put("data",vos);}
2)封装
输出层Vo
package com.atguigu.gulimall.product.vo;import com.atguigu.gulimall.product.entity.AttrEntity;import com.baomidou.mybatisplus.annotation.TableId;import lombok.Data;import java.util.List;@Datapublic class AttrGroupWithAttrsVo { private List<AttrEntity> attrs;}
3)添加Service 添加
实现方法
/** * 根据分类id查出所有的分组以及这些组里面的属性 * @param catelogId * @return */@Overridepublic List getAttrGroupWithAttrsByCatelogId(Long catelogId) { //com.atguigu.gulimall.product.vo //1、查询分组信息 List attrGroupEntities = this.list(new QueryWrapper().eq("catelog_id", catelogId)); //2、查询所有属性 List collect = attrGroupEntities.stream().map(group -> { AttrGroupWithAttrsVo attrsVo = new AttrGroupWithAttrsVo(); BeanUtils.copyProperties(group,attrsVo); List attrs = attrService.getRelationAttr(attrsVo.getAttrGroupId()); attrsVo.setAttrs(attrs); return attrsVo; }).collect(Collectors.toList()); return collect;}
得到效果,获取到对应的分组展示在左侧,对应的
3.新增商品第三步,编写sku 信息
在编辑完销售属性,如下图所示,即可根据对应关系, 生成出sku 信息 生成的sku 列表如下 添加对应的 副标题,和价格信息 设置 明细信息4.根据提交json 生成实体类
编辑完成所有信息信息会发送大量的信息到后端,接口处进行 保存操作 查找 Json 转换工具 进行格式化,便于观察 选择生成实体类,功能 输入类名和指定包名,自动封装成多个实体类 得到效果,即可获得多个Vo,和 相关封装的实体类-END-
可以关注我的公众号,免费获取价值1980元学习资料
点击“在看”,学多少都不会忘~