1. 程式人生 > >使用PageHelper外掛分頁結合mybatis返回的列表個數不對問題解決

使用PageHelper外掛分頁結合mybatis返回的列表個數不對問題解決

問題描述:spring mvc+mybatis專案中,當使用PageHelper外掛進行分頁查詢時,查到的總資料量值是正確的,但是查詢當前頁返回的列表個數不對。比如每頁查詢10條,返回2條或者3條。resultMap使用了association返回複雜屬性。

格式如下:

<resultMap type="orgDetail" id="porgDetailMap">
        <result property="" column="" />
        <association property="orgInfo"
            javaType="com.sinosig.jobSpace.orgmanage.model.BaseOrgModel">
            <id property="id" column="id" />
            <result property="" column="" />
            <result property="" column="" />
            <result property="" column="" />
            <result property="" column="" />
            <result property="" column="" />
        </association>

    </resultMap>

產生問題的原因是當resultMap使用<result />  <association/>返回,當<result />對應的屬性有重複值時,只加載一個。

解決方法:

resultMap中增加<id />的返回,保證資料的唯一性(出自http://blog.51cto.com/7532113/1908701)

我的問題是根據需要唯一的資料的那張表進行左連線而不是內連線