基本思路:对基表进行分页,而不是针对最后的查询结果
<resultMap type="com.web.model.Test" id="TestMap">
<id property="systemid" column="systemid"/>
<result property="create_time" column="create_time"/>
<collection property="test_extend_info" ofType="com.web.model.Test_extend">
<id property="info" column="info"/>
<result property="status" column="status"/>
</collection>
</resultMap>
分页sql
<sql id="pageHeader">
select * from ( select a.*, rownum rn from (
</sql>
<sql id="pageRoot">
) a where rownum <= #{rowEnd} ) where rn > #{rowStart}
</sql>
基表查询sql
<sql id="getTestInfoBasic">
select *
from t_test a
<where>
……
</where>
order by create_time desc
</sql>
对基表进行分页sql
<sql id="getTestInfo">
select t.systemid, t.create_time, e.info, e.status
from (
<include refid = "pageHeader" />
<include refid = "getTestInfoBasic" />
<include refid = "pageRoot" />
) t
left join
t_test_extend e
on t.systemid = e.systemid
</sql>
结果查询sql
<select id="getTestInfoCount" resultType="java.lang.Integer">
select count(systemid) from ( <include refid = "getTestInfoBasic" /> )
</select>
<select id="getTestInfoByOrgId" resultMap="TestMap">
select * from ( <include refid = "getTestInfo" /> )
</select>