使用 myBatis 返回 ResultMap 中的总行数
我为此扩展 ResultMap 创建了两个附加字段 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>
我该如何解决这个问题?
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_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>
How can I get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,不在同一查询中。
为 SELECT 语句返回的每条记录的每个条目添加两列,因为这就是它返回的内容。为了获取返回的总行数,您可以触发第二个查询或获取返回的集合的大小。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.