![](/img/trans.png)
[英]MyBatis dynamic ResultMap. How to return list of different POJO objects?
[英]Return total count of rows in ResultMap with myBatis
我為此擴展ResultMap創建了2個附加字段rowNumber和totalRows。 是的,現在我有了總行數,但它存儲在結果圖中的每個對象中。
<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 >= #{pageInfo.startRow} AND row_number < #{pageInfo.endRow}
order by row_number ASC
</select>
我該如何解決?
不,不在同一查詢中。 <resultMap/>
將為SELECT語句返回的每個記錄的每個條目添加兩列,因為這是它返回的內容。 為了獲得返回的總行數,您可以觸發第二個查詢或獲取返回的集合的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.