开发者

Return total count of rows in ResultMap with myBatis

开发者 https://www.devze.com 2023-02-22 09:32 出处:网络
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.

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 &gt;= #{pageInfo.startRow} AND row_number &lt; #{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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号