mybatis 一对多分页查询数据条数不匹配解决

mysql find_in_set

原因

在项目中,使用mybatis做一对多关联,出现数据条数不匹配的情况,比如要查询10条,由于一对多的关系导致最终得到的数据条数变少。

解决方案(1)

<select id="list" parameterType="emro.vo.resource.ResourceConfigDetailSearchVo" resultMap="resourceConfigDetails">
    SELECT
      detail.id id,
      detail.activity_name activityName,
      detail.main_title mainTitle,
      detail.main_title_spec mainTitleSpec,
      detail.sub_title subTitle,
      detail.desc_copy descCopy,
      detail.order_sn orderSn,
      detail.start_time startTime,
      detail.end_time endTime,
      detail.enable enable,
      detail.user_tag userTag,
      detail.pic_num picNum,
      detail.tag tag,
      detail.terminal_type terminalType,
      detail.pop_rate popRate,
      detail.status status,
      detail.create_name createName,
      detail.create_time createTime,
      detail.update_name updateName,
      detail.update_time updateTime,
      item.detail_id detailId,
      item.pc_image pcImage,
      item.pc_jump_url pcJumpUrl,
      item.background_color backgroundColor,
      item.mobile_image mobileImage,
      item.app_jump_url appJumpUrl,
      item.mp_jump_url mpJumpUrl
    FROM
    resource_config_detail detail
    LEFT JOIN resource_config_detail_item item ON detail.id = item.detail_id
    WHERE
    detail.id IN (IFNULL((SELECT temp.id
    FROM (SELECT config_detail.id FROM
    resource_config_detail config_detail
    where config_detail.status='1'
    <include refid="queryTerm"/>
    ORDER BY config_detail.order_sn DESC,config_detail.end_time DESC
    limit #{page},#{rows}) AS temp),''))
  </select>

解决方案(二)

 <id property="id" column="id"/>
 
<collection property="items"    ofType="com.test..domain.BookDetail"
                   column="id" select="com.test.dao.BookDetailDao.getCheckItemInfo"/>
posted @ 2021-04-16 13:40  朝明  阅读(1727)  评论(0编辑  收藏  举报