I create for this extended ResultMap with 2 additional fields rowNumber and totalRows. Yes, now I have total rows count, but it stores in every object from result map.
<resultMap id="BaseResultMapPagination" type="com.example.emaildto.EmailScheduleDTO" extends="BaseResultMap">
<result property="rowNumber" column="row_number"/>
<result property="totalRows" column="total_count"/>
</resultMap>
<select id="selectByExamplePagination" resultMap="BaseResultMapPagination" parameterType="com.example.emailservice.model.EmailScheduleCriteria">
WITH t as (
select row_numb开发者_Python百科er() OVER(<include refid="orderByPagination"/>) as row_number,
count(*) OVER () as total_count,
* from EmailSchedule t
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
)
select * from t where row_number >= #{pageInfo.startRow} AND row_number < #{pageInfo.endRow}
order by row_number ASC
</select>
How can I get around this?
No, not within the same query. The <resultMap/>
is adding two columns to each entry for each record returned from your SELECT statement because this is what it returns. In order to get the total number of rows returned you could, instead, fire off a second query or get the size of the collection returned.
精彩评论