2011-04-04 39 views
0

我爲此擴展ResultMap創建了兩個附加字段rowNumber和totalRows。是的,現在我有總計行數,但它存儲在結果地圖中的每個對象。使用myBatis返回ResultMap中行的總計數

<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_number() 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 &gt;= #{pageInfo.startRow} AND row_number &lt; #{pageInfo.endRow} 
order by row_number ASC 
</select> 

我該如何解決這個問題?

回答

0

不,不在相同的查詢中。 <resultMap/>爲從SELECT語句返回的每條記錄的每個條目添加兩列,因爲這是它返回的內容。爲了獲得返回的行數,您可以取消第二個查詢或獲取返回的集合的大小。