专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-683-0016      微信咨询  |  联系我们

mybatis_collection用法,懒加载,一对多

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/2/14 1:03:34       共计:3654 浏览

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

版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:MyBatis框架collection属性和collection标签的用法详细介绍 | ·下一条:MyBatis collection的两种形式

Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有