商品服务-商品维护-SPU规格维护

34 篇文章 0 订阅
32 篇文章 0 订阅

1.接口文档

在这里插入图片描述

2.AttrController中添加baseAttrListForSPU方法

 /**
   * 获取spu规格
   * @param spuId
   * @return
   */
  @GetMapping("/base/listforspu/{spuId}")
  public R baseAttrListForSPU(@PathVariable("spuId") Long spuId){
      List<ProductAttrValueEntity> productAttrValueEntityList = productAttrValueService.baseAttrListForSPU(spuId);
      return R.ok().put("data",productAttrValueEntityList);
  }

3.ProductAttrValueService中添加baseAttrListForSPU方法

List<ProductAttrValueEntity> baseAttrListForSPU(Long spuId);

4.ProductAttrValueServiceImpl中添加baseAttrListForSPU方法实现

 /**
   * 获取spu规格
   * @param spuId
   * @return
   */
@Override
public List<ProductAttrValueEntity> baseAttrListForSPU(Long spuId) {
    List<ProductAttrValueEntity> productAttrValueEntityList = this.baseMapper.selectList(
            new QueryWrapper<ProductAttrValueEntity>().eq("spu_id", spuId));
    return productAttrValueEntityList;
}

5.前端bug修改

bug:在spu管理中点击规格,前端显示404
在这里插入图片描述
用post测试:成功获取数据
在这里插入图片描述
问题分析: 前端路由问题
解决方案:在src/router/index.js的mainRoutes的children中配置spu管理–>规格的路由
在这里插入图片描述

// 主入口路由(需嵌套上左右整体布局)
const mainRoutes = {
  path: '/',
  component: _import('main'),
  name: 'main',
  redirect: { name: 'home' },
  meta: { title: '主入口整体布局' },
  children: [
    // 通过meta对象设置路由展示方式
    // 1. isTab: 是否通过tab展示内容, true: 是, false: 否
    // 2. iframeUrl: 是否通过iframe嵌套展示内容, '以http[s]://开头': 是, '': 否
    // 提示: 如需要通过iframe嵌套展示内容, 但不通过tab打开, 请自行创建组件使用iframe处理!
    { path: '/home', component: _import('common/home'), name: 'home', meta: { title: '首页' } },
    { path: '/theme', component: _import('common/theme'), name: 'theme', meta: { title: '主题' } },
    { path: '/demo-echarts', component: _import('demo/echarts'), name: 'demo-echarts', meta: { title: 'demo-echarts', isTab: true } },
    { path: '/demo-ueditor', component: _import('demo/ueditor'), name: 'demo-ueditor', meta: { title: 'demo-ueditor', isTab: true } },
    // 商品系统--商品维护-- spu管理 --规格
    { path: '/product-attrupdate', component: _import('modules/product/attrupdate'), name: 'attr-update', meta: { title: '规格维护', isTab: true } }
  ],

重启再次访问
在这里插入图片描述

6.修改商品规格

在这里插入图片描述

6.1.AttrController中添加updateSpuAttr方法

 /**
   * 修改商品规格
   * @param spuId
   * @param entities
   * @return
   */
  @PostMapping("/update/{spuId}")
  public R updateSpuAttr(@PathVariable("spuId") Long spuId,
                         @RequestBody List<ProductAttrValueEntity> entities){
      productAttrValueService.updateSpuAttr(spuId,entities);
      return R.ok();
  }

6.2.ProductAttrValueService中添加updateSpuAttr

void updateSpuAttr(Long spuId, List<ProductAttrValueEntity> entities);

6.3.ProductAttrValueServiceImpl中添加updateSpuAttr方法实现

/**
  * 修改商品规格
  * @param spuId
  * @param entities
  */
 @Transactional
 @Override
 public void updateSpuAttr(Long spuId, List<ProductAttrValueEntity> entities) {
     //1、删除这个spuId之前对应的所有属性
     this.baseMapper.delete(
             new QueryWrapper<ProductAttrValueEntity>().eq("spu_id",spuId));

     List<ProductAttrValueEntity> productAttrValueEntityList = entities.stream().map(item -> {
         item.setSpuId(spuId);
         return item;
     }).collect(Collectors.toList());
     this.saveBatch(productAttrValueEntityList);
 }

在这里插入图片描述

.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值