关于mybatis一对多分页数据缺失情况

一对多字段映射
<resultMap id="SubjectNameOTD" type="com.tj.vo.SubjectNameOTD">
    <id column="subject_code" jdbcType="VARCHAR" property="subjectCode" />
    <association property="subjectName" javaType="com.tj.vo.SubjectName">
        <result column="dept_code" jdbcType="VARCHAR" property="deptCode" />
        <result column="dept_name" jdbcType="VARCHAR" property="deptName" />
        <result column="subject_code" jdbcType="VARCHAR" property="subjectCode" />
        <result column="subject_name" jdbcType="VARCHAR" property="subjectName" />
    </association>
    <collection property="subItemsNameList" ofType="com.tj.vo.SubItemsName"  column="subject_code" select="selectChildren">
    </collection>
</resultMap>

主查询
<select id="selectDirectoryItemsList02"  resultMap="SubjectNameOTD">
  select id,dept_code,dept_name,subject_code,subject_name,subitem_code,subitem_name
  from directory_listing_code
  <where>
    <if test="subjectName!=null and subjectName!=''">
      subject_name like '%' #{subjectName} '%' or subitem_name like '%' #{subjectName} '%'
    </if>
    <if test="deptCode!=null and deptCode!=''">
    and dept_code like '%' #{deptCode} '%'
    </if>
  </where>
  group  by  subject_code
</select>

子查询
  <select id="selectChildren"  parameterType="java.lang.String" resultType="com.tj.vo.SubItemsName">
      select subitem_code as subitemCode,subitem_name as subitemName
      from directory_listing_code
      where subject_code=#{subjectCode}
  </select>

分为两次查询主查询和子查询,在主查询进行分页处理,再通过column传递外键关系进行子查询,就不会出现分页数据丢失情况。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值