使用 myBatis 返回 ResultMap 中的总行数

发布于 2024-10-30 03:12:13 字数 963 浏览 0 评论 0原文

我为此扩展 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 &gt;= #{pageInfo.startRow} AND row_number &lt; #{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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混吃等死 2024-11-06 03:12:13

不,不在同一查询中。 为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文