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

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. 出现原因:

后期补充

你可能感兴趣的:(MySQL,开发常见错误,mybatis,mysql,sql)