21.商品详情

环境搭建

修改域名

21.商品详情

 

 

 修改网关

让item也能跳到商品服务

21.商品详情

 

 

 前端内容放入nginx

模型抽取

product模块里封装Vo,由于下面两个属性需要在mapper里映射结果集使用,所以不能写成静态内部类

@Data
public class SkuItemVo {
    private SkuInfoEntity info; //1.查询当前sku的基本信息 sku_info表
    private List<SkuImagesEntity> images; //2.sku的图片信息 pms_sku_image
    private List<SkuItemSaleAttrsVo> saleAttrsVos;  //3.获取spu的销售属性组合
    private SpuInfoDescEntity desp; //4.获取spu的介绍
    private List<SpuItemAttrGroup> groupAttrs;//5.获取spu的规格参数
    @ToString
    @Data
    public static class SkuItemSaleAttrsVo {
        private Long attrId;
        private String attrName;
        private List<String> attrValues;
    }
    @ToString
    @Data
    public class SpuItemAttrGroup{
        private String groupName;

        /** 两个属性attrName、attrValue */
        private List<SpuBaseAttrVo> attrs;
    }
    @ToString
    @Data
    public class  SpuBaseAttrVo{
        private String attrName;
        private String attrValue;
    }
}

规格参数--连表查询

想获取规格参数的sql,把需要用到的字段可以起上别名

SELECT pav.`spu_id`,ag.`attr_group_name` gorupName,ag.`attr_group_id`,aar.`attr_id`,attr.`attr_name` attrName,pav.`attr_value` attrValue
FROM `pms_attr_group` ag 
LEFT JOIN `pms_attr_attrgroup_relation` aar ON aar.`attr_group_id`=ag.`attr_group_id` 
LEFT JOIN `pms_attr` attr ON attr.`attr_id`=aar.`attr_id`
LEFT JOIN `pms_product_attr_value` pav ON pav.`attr_id`=attr.`attr_id`
WHERE ag.catelog_id=225 AND pav.`spu_id`=3

查询出来的结果

21.商品详情

 

 具体方法

21.商品详情

<!--有嵌套属性的时候要封装自定义结果集-->
    <resultMap id="spuItemAttrGroupVo" type="com.*min.gulimall.product.vo.SpuItemAttrGroup">
        <result property="groupName" column="groupName"></result>
        <collection property="attrs" ofType="com.*min.gulimall.product.vo.SpuBaseAttrVo">
            <result property="attrName" column="attrName"></result>
            <result property="attrValue" column="attrValue"></result>
        </collection>
    </resultMap>
    <select id="getAttrGroupWithAttrsBySpuId"
            resultMap="spuItemAttrGroupVo">
    SELECT pav.`spu_id`,ag.`attr_group_name` gorupName,ag.`attr_group_id`,aar.`attr_id`,attr.`attr_name` attrName,pav.`attr_value` attrValue
    FROM `pms_attr_group` ag
    LEFT JOIN `pms_attr_attrgroup_relation` aar ON aar.`attr_group_id`=ag.`attr_group_id`
    LEFT JOIN `pms_attr` attr ON attr.`attr_id`=aar.`attr_id`
    LEFT JOIN `pms_product_attr_value` pav ON pav.`attr_id`=attr.`attr_id`
    WHERE ag.catelog_id=#{catalogId} AND pav.`spu_id`=#{spuId}
    </select>

方法测试

    @Test
    void test(){
        List<SpuItemAttrGroup> attrGroupWithAttrsBySpuId = attrGroupDao.getAttrGroupWithAttrsBySpuId(3L, 225L);
        attrGroupWithAttrsBySpuId.forEach(System.out::println);
    }

测试结果

21.商品详情

 

上一篇:mac安装php


下一篇:一加7 nethunter + andrax + parrot 开机指导