需求: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字段是否存在,是否正确

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐