• 【微服务】Day09


    开发酷鲨前台商品列表

    按分类id分页查询spu列表

    用户会根据分类树中的分类的名称,查询它需要的商品类别

    点击商品分类名称时,实际上我们获得了它的分类id(categoryId)

    我们可以根据这个id到pms_spu表中查询商品信息

    并进行分页显示

    这个查询目标仍然为mall-pms数据库,是product模块管理的范围

    所以我们在业务逻辑层中编写利用dubbo调用即可,还是不需要写mapper

    下面就在业务逻辑层中创建FrontProductServiceImpl

    @Service
    @Slf4j
    public class FrontProductServiceImpl implements IFrontProductService {
       
    
        @DubboReference
        private IForFrontSpuService dubboSpuService;
    
        @Override
        public JsonPage<SpuListItemVO> listSpuByCategoryId(Long categoryId, Integer page, Integer pageSize) {
       
            // IForFrontSpuService实现类中完成了分页查询的业务操作,我们直接调用即可
            JsonPage<SpuListItemVO> list=
                    dubboSpuService.listSpuByCategoryId(categoryId,page,pageSize);
            // 返回 list!!!!!
            return list;
        }
    
        @Override
        public SpuStandardVO getFrontSpuById(Long id) {
       
            return null;
        }
    
        @Override
        public List<SkuStandardVO> getFrontSkusBySpuId(Long spuId) {
       
            return null;
        }
    
        @Override
        public SpuDetailStandardVO getSpuDetail(Long spuId) {
       
            return null;
        }
    
        @Override
        public List<AttributeStandardVO> getSpuAttributesBySpuId(Long spuId) {
       
            return null;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    业务逻辑层实现类先只实现按分类id分页查询的功能即可

    创建FrontSpuController编写调用代码如下

    @RestController
    @RequestMapping("/front/spu")
    @Api(tags = "前台商品spu模块")
    public class FrontSpuController {
       
    
        @Autowired
        private IFrontProductService frontProductService;
    
        // localhost:10004/front/spu/list/3
        @GetMapping("/list/{categoryId}")
        @ApiOperation("根据分类id分页查询Spu列表")
        @ApiImplicitParams({
       
                @ApiImplicitParam(value = "分类id",name="categoryId",example = "3"),
                @ApiImplicitParam(value = "页码",name="page",example = "1"),
                @ApiImplicitParam(value = "每页条数",name="pageSize",example = "2")
        })
        public JsonResult<JsonPage<SpuListItemVO>> listSpuByPage(
                @PathVariable Long categoryId, Integer page, Integer pageSize){
       
            JsonPage<SpuListItemVO> jsonPage=
                    frontProductService.listSpuByCategoryId(categoryId,page,pageSize);
            return JsonResult.ok(jsonPage);
    
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    然后在Nacos\Seata\Redis启动的前提下

    顺序启动Product\Front

    进行测试

    http://localhost:10004/doc.html

    查询商品详情页信息

    上面章节完成了查询spu列表

    在商品列表中选中商品后,会显示这个商品的详情信息

    商品详情页我们需要显示的信息包括

    • 根据spuId查询spu信息
    • 根据spuId查询spuDetail详情
    • 根据spuId查询当前Spu包含的所有属性
    • 根据spuId查询对应的sku列表

    其中根据spuId查询当前Spu包含的所有属性功能涉及了一个比较复杂的连表查询

    根据spuId查询参数选项的思路

    1.根据spu_id去pms_spu表查询category_id

    2.根据category_id去pms_category表查询分类对象

    3.根据category_id去pms_category_attribute_template表查询attribute_template_id

    4.根据attribute_template_id去pms_attribute_template表查询attribute_template数据行

    5.根据attribute_template_id去pms_attribute表查询对应所有属性信息行

    实际上,上面的联表查询可以简化为3表联查,结果相同

  • 相关阅读:
    已解决ValueError: More than 4094 XFs (styles)
    庖丁解牛:NIO核心概念与机制详解 04 _ 分散和聚集
    时间同步设置NTP和Chrony两种方式—— 筑梦之路
    为什么选择 TypeScript
    什么样的vue面试题答案才是面试官满意的
    混淆加密JS,可以压缩代码体积吗?
    Ruby on Rails 实践:课程导读
    vue~要懂的有关node与npm
    【UGUI】给美术的备忘录
    C# string字符串内存管理深入分析(全程干货)
  • 原文地址:https://blog.csdn.net/shortcutsuccess/article/details/127131000