mybatisplus新增返回主键_SpringCloud微服务开发 之十七 后台管理系统(十四)新增商品规格...

4c329b2da982992e1c22cca15bc67c55.png

本文包含以下内容:

  1. 获取分类的品牌关系列表

  2. 新增商品第二步,根据属性获取所有的属性接口

  3. 新增商品第三步,编写sku 信息

  4. 根据提交json 生成实体类

1.获取分类的品牌关系列表

接上文,添加商品选择完分类,显示报错,查詢分类和品牌关系,的接口 404,找不到,所以添加新的接口

f9b9480527b6ad248e3b1685ad5ad16a.png

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;}

得到效果,可以查詢到指定分类下的品牌

9fc61adde52fbfae99b8b6e995ec7785.png

2.新增商品第二步,根据属性获取所有的属性接口

进入添加商品第二步,查詢分类关联的属性分组,对应的规格参数,接口 404,尚未编写

2fcd43c71bf064b2480fe28c1a42f306.png

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;}
得到效果,获取到对应的分组展示在左侧,对应的

9b93e19a1c7614b1f0df48d8d7f6bbc5.png

3.新增商品第三步,编写sku 信息

在编辑完销售属性,如下图所示,即可根据对应关系, 生成出sku 信息

46190d07b0bf78a4b3781ef7e96a8b21.png

生成的sku 列表如下

4faccdedded1abad86c2caf4e4064834.png

添加对应的 副标题,和价格信息

a96ff5289dfa05b9daf36d3690d8371b.png

设置 明细信息

5ee27848a1291a88af5c0f85e2cdb1a1.png

4.根据提交json 生成实体类

编辑完成所有信息信息会发送大量的信息到后端,接口处进行 保存操作

0161fa432b4516b826fe73c73925aff1.png

查找 Json 转换工具

b51b7e256ef9ae7d1c12d962f5a7f060.png

进行格式化,便于观察

3329d3032ea2f930fd4dd505e898d3ff.png

选择生成实体类,功能

25792f4d16552cc9c07889214012b4ad.png

输入类名和指定包名,自动封装成多个实体类

c538a34c6a65e595244f751993f8f9d7.png

得到效果,即可获得多个Vo,和 相关封装的实体类

ed52914b58f6231488497c0842cfe8bd.png

-END-

2bec7001c6401281ace958247ce66a30.png

可以关注我的公众号,免费获取价值1980元学习资料

点击“在看”,学多少都不会忘~

bcb35c3de13b32132bbec729b025d0b9.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值