[英]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.