Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

老哥的AttrGroupDao.xml中resultMap漏写了 #2

Open
huangxiao1234 opened this issue May 7, 2021 · 1 comment
Open

老哥的AttrGroupDao.xml中resultMap漏写了 #2

huangxiao1234 opened this issue May 7, 2021 · 1 comment

Comments

@huangxiao1234
Copy link

huangxiao1234 commented May 7, 2021

对应P205
不改的话类型映射会出问题
这里会遇到一个问题,就是方法getAttrGroupWithAttrsBySpuId明明指定了返回类型为List(SpuItemAttrGroupVo)
漏写resultmap的话,返回类型为List(AttGroupEntity)居然不报错?

`

<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.zsy.product.entity.AttrGroupEntity" id="attrGroupMap">
    <result property="attrGroupId" column="attr_group_id"/>
    <result property="attrGroupName" column="attr_group_name"/>
    <result property="sort" column="sort"/>
    <result property="descript" column="descript"/>
    <result property="icon" column="icon"/>
    <result property="catelogId" column="catelog_id"/>
</resultMap>
<resultMap id="spuItemAttrGroupVo" type="com.zsy.product.vo.SpuItemAttrGroupVo">
    <result property="groupName" column="attr_group_name"></result>
    <collection property="attrs" ofType="com.zsy.product.vo.Attr">
        <result column="attr_name" property="attrName"></result>
        <result column="attr_value" property="attrValue"></result>
    </collection>
</resultMap>

<select id="getAttrGroupWithAttrsBySpuId" resultMap="spuItemAttrGroupVo">
    SELECT
        product.spu_id,
        pag.attr_group_id,
        pag.attr_group_name,
        product.attr_id,
        product.attr_name,
        product.attr_value
    FROM
        pms_product_attr_value product
            LEFT JOIN pms_attr_attrgroup_relation paar ON product.attr_id = paar.attr_id
            LEFT JOIN pms_attr_group pag ON paar.attr_group_id = pag.attr_group_id
    WHERE
        product.spu_id = #{spuId}
      AND pag.catelog_id = #{catalogId}

</select>
`
@zsy0216
Copy link
Owner

zsy0216 commented May 8, 2021

对应P205
不改的话类型映射会出问题
这里会遇到一个问题,就是方法getAttrGroupWithAttrsBySpuId明明指定了返回类型为List(SpuItemAttrGroupVo)
漏写resultmap的话,返回类型为List(AttGroupEntity)居然不报错?

`

<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.zsy.product.entity.AttrGroupEntity" id="attrGroupMap">
    <result property="attrGroupId" column="attr_group_id"/>
    <result property="attrGroupName" column="attr_group_name"/>
    <result property="sort" column="sort"/>
    <result property="descript" column="descript"/>
    <result property="icon" column="icon"/>
    <result property="catelogId" column="catelog_id"/>
</resultMap>
<resultMap id="spuItemAttrGroupVo" type="com.zsy.product.vo.SpuItemAttrGroupVo">
    <result property="groupName" column="attr_group_name"></result>
    <collection property="attrs" ofType="com.zsy.product.vo.Attr">
        <result column="attr_name" property="attrName"></result>
        <result column="attr_value" property="attrValue"></result>
    </collection>
</resultMap>

<select id="getAttrGroupWithAttrsBySpuId" resultMap="spuItemAttrGroupVo">
    SELECT
        product.spu_id,
        pag.attr_group_id,
        pag.attr_group_name,
        product.attr_id,
        product.attr_name,
        product.attr_value
    FROM
        pms_product_attr_value product
            LEFT JOIN pms_attr_attrgroup_relation paar ON product.attr_id = paar.attr_id
            LEFT JOIN pms_attr_group pag ON paar.attr_group_id = pag.attr_group_id
    WHERE
        product.spu_id = #{spuId}
      AND pag.catelog_id = #{catalogId}

</select>

`

多谢,确实少写了,没注意到这个地方。

zsy0216 added a commit that referenced this issue May 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants