简体   繁体   English

使用myBatis返回ResultMap中的行总数

[英]Return total count of rows in ResultMap with myBatis

I create for this extended ResultMap with 2 additional fields rowNumber and totalRows. 我为此扩展ResultMap创建了2个附加字段rowNumber和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_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>

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. <resultMap/>将为SELECT语句返回的每个记录的每个条目添加两列,因为这是它返回的内容。 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. 为了获得返回的总行数,您可以触发第二个查询或获取返回的集合的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM