com.github.pagehelper分页插件优化

发布时间 2023-11-21 11:25:20作者: 白玉神驹

重写插件查询sql总返回条数方法

原sql,如果表很大会导致分页查询耗时很久

<select id="findUser" resultType="com.x.x.x.entity">
select count(0) from (select a.x,a.y,............from user_info where .....) tmp_count
</select>

例子

 优化sql,重写插件统计方法

在mybatis中调整
1. 复制原方法并在方法名称上加上 _COUNT
2. 返回的结果类型为Long
3. 统计时返回值为1(最简即可),需要一个临时表名称tmp_count
<select id="findUser_COUNT" resultType="java.lang.Long">
select count(0) from (select 1 from user_info where .....) tmp_count
</select>

优化后