mybatis collection用法,懒加载,一对多

需求:li_store商城主表,li_banner,li_goods商品表,li_store_hit_call打call记录表

接口:查询获取列表,需要根据打call记录表排序,展示主表信息,商品list , banner list

封装返回对象

@Data
public class HitCallListVO implements Serializable {
    private String storeId;
    private String logo;
    private String storeName;
    private Integer count;
    private List<StoreBanner> bannerList;
    private List<GoodsRecommend> recommendList;
}

mybatis mapper.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.lili.modules.store.mapper.StoreHitCallMapper">

    <resultMap id="resultMap" type="cn.lili.modules.store.entity.vos.HitCallListVO">
        <result property="storeId" column="id"/>
        <result property="storeName" column="store_name"/>
        <result property="logo" column="store_logo"/>
        <result property="count" column="count"/>
        <collection property="bannerList"
                    javaType="list"
                    ofType="cn.lili.modules.store.entity.dos.StoreBanner"
                    select="cn.lili.modules.store.mapper.StoreHitCallMapper.getBannerListByStoreId"
                    column="id">
        </collection>
        <collection property="recommendList"
                    javaType="list"
                    ofType="cn.lili.modules.recommend.entity.GoodsRecommend"
                    select="cn.lili.modules.store.mapper.StoreHitCallMapper.getGoodsByStoreId"
                    column="id">
        </collection>
    </resultMap>
    
    <select id="selectCallPage" resultMap="resultMap">
        select
            case WHEN a.count is null then 0 else a.count end as `count`,
            d.id,
            d.store_logo,
            d.store_name
        from li_store d
            left join li_store_hit_call a
        on a.store_id = d.id
        order by `count` desc
    </select>
    <select id="getBannerListByStoreId" resultType="cn.lili.modules.store.entity.dos.StoreBanner">
        select
            *
        from li_store_banner
        where
              store_id = #{storeId}
          and delete_flag = 0
    </select>
    <select id="getGoodsByStoreId" resultType="cn.lili.modules.recommend.entity.GoodsRecommend">
        select
            *
        from li_goods_recommend
        where store_id = #{storeId}
          and delete_flag = 0
    </select>
</mapper>

collection不执行问题:

  • 检查主查询
    <select id="selectCallPage" resultMap="resultMap">
    <resultMap id="resultMap" type="cn.lili.modules.store.entity.vos.HitCallListVO">
    resultMap是否对应
  • column字段是否存在,是否正确

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值