mybatis分页插件一对多查询数据丢失问题

本文介绍了解决MyBatis中数据总数与实际显示数量不符的问题,通过使用子查询映射来确保数据显示正确。具体实现包括定义resultMap、查询主表及子表等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.问题

总条数显示有三条数据,列表展示却只有两条

2.解决办法:

使用mybatis子查询映射

<resultMap id="resultHouseholdList" type="com..HouseholdListPageVO">
        <result column="id" property="id" jdbcType="VARCHAR"/>
        <result column="ownerName" property="ownerName" jdbcType="VARCHAR"/>
        <result column="projectName" property="projectName" jdbcType="VARCHAR"/>
        <collection property="imageList" select="selectImageList" column="id" ofType="com.HouseholdImageListVO">
        </collection>
    </resultMap>
<select id="findHouseholdListByCondition" resultMap="resultHouseholdList">
        SELECT
            ihr.id,
            ihr.project_name as projectName,
            ihr.house_name as houseName,
            ihr.status,
            ihr.owner_name as ownerName,
            ihr.id_card as idCard,
            ihr.telephone,
            ihr.track,
            ihr.receive,
            ihr.create_time as createTime
        FROM
            iso_household_register ihr
        WHERE
            ihr.owner_register_id IS NULL
            and status = 2
    </select>
    <select id="selectImageList" resultType="com.HouseholdImageListVO">
        select * from iso_household_register_image image
            where image.household_register_id = #{id}
    </select>

3. 出现原因:

后期补充

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值