Mybites一对多collection

    
    
    Goods实体属性:
        private List<GoodsImg> goodsImgList;
        private String id;
        private String name;
    GoodsImg实体属性:
        private String id;
        private String fid;
        private String imgpath;
        private String basepath;
        
    第一种:(collection分页有问题,一般用于条件查询)
        <resultMap id="resultGoodsMap" type="com.ceshi.model.Goods">
            <id column="id" property="id" jdbcType="VARCHAR" />
            <result column="name" property="name" jdbcType="VARCHAR" />
            <collection property="goodsImgList" ofType="com.ceshi.model.GoodsImg">
                <id column="i_id" property="id" jdbcType="VARCHAR" />
                <result column="i_fid" property="fid" jdbcType="VARCHAR" />
                <result column="i_imgpath" property="imgpath" jdbcType="LONGVARCHAR" />
                <result column="i_basepath" property="basepath" jdbcType="LONGVARCHAR" />
            </collection>
        </resultMap>
        
        <!--查询商品信息-->
        <select id="selectGoods" resultMap="resultGoodsMap">
            SELECT g.id AS id, g.name AS name, i.id AS i_id, i.fid AS i_fid, i.imgpath AS i_imgpath, i.basepath AS i_basepath
            FROM crm_goods g
            LEFT JOIN crm_goods_img i ON g.id = i.fid
            WHERE g.id = #{id} <!--一般用于查询具体商品信息-->
        </select>
    
    第二种:(效率低,但是可以解决collection分页问题)
        <resultMap id="resultGoodsMap" type="com.ceshi.model.Goods">
            <id column="id" property="id" jdbcType="VARCHAR" />
            <result column="name" property="name" jdbcType="VARCHAR" />
            <collection property="goodsImgList" ofType="com.ceshi.model.GoodsImg" select="selectGoodsImg" column="{fid = id}"></collection>
        </resultMap>

        <resultMap id="resultGoodsImgMap" type="com.ceshi.model.GoodsImg">
            <id column="i_id" property="id" jdbcType="VARCHAR" />
            <result column="i_fid" property="fid" jdbcType="VARCHAR" />
            <result column="i_imgpath" property="imgpath" jdbcType="LONGVARCHAR" />
            <result column="i_basepath" property="basepath" jdbcType="LONGVARCHAR" />
        </resultMap>
        
        <!--查询商品信息-->
        <select id="selectGoods" resultMap="resultGoodsMap">
            SELECT g.id AS id, g.name AS name
            FROM crm_goods g
        </select>
        
        <!--根据商品id查询商品图片信息-->
        <select id="selectGoodsImg" resultMap="resultGoodsImgMap">
            SELECT i.id AS i_id, i.fid AS i_fid, i.imgpath AS i_imgpath, i.basepath AS i_basepath
            FROM crm_goods_img i
            WHERE i.fid = #{fid}
        </select>

相关推荐

  1. Mybitescollection

    2024-04-14 13:50:03       34 阅读
  2. Collections.reverselist进行反转

    2024-04-14 13:50:03       55 阅读
  3. JPA的复杂查询包括多多的查询

    2024-04-14 13:50:03       51 阅读
  4. [Django-04]一对一,

    2024-04-14 13:50:03       63 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-14 13:50:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-14 13:50:03       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-14 13:50:03       82 阅读
  4. Python语言-面向对象

    2024-04-14 13:50:03       91 阅读

热门阅读

  1. 06篇 Linux命令练习

    2024-04-14 13:50:03       33 阅读
  2. 开关门c++

    2024-04-14 13:50:03       33 阅读
  3. 逐步学习Go-Slice(切片还可以多挖一下)

    2024-04-14 13:50:03       33 阅读
  4. `/bin/bash`、`sh` 或者直接./的区别

    2024-04-14 13:50:03       40 阅读
  5. js如何实现修改URL参数并不刷新页面

    2024-04-14 13:50:03       35 阅读
  6. MongoDB聚合运算符:$percentile

    2024-04-14 13:50:03       36 阅读
  7. 如何判断服务器的线路

    2024-04-14 13:50:03       38 阅读