Closed Pink-Starfish closed 11 months ago
在执行new PageInfo时
public PageSerializable(List<? extends T> list) {
this.list = (List<T>) list;
if(list instanceof Page){
this.total = ((Page<?>)list).getTotal();
} else {
this.total = list.size();
}
}
这个if总是为false,因为这个查询是我自己写的,返回的就是一个List。
我还测试了,startPage,结果也是如此,sql跟offset分页时的sql是一模一样的。
如果pagehelper分页插件起作用,返回的List实际类型一定是Page。
如果pagehelper分页插件起作用,返回的List实际类型一定是Page。 你的意思是我的分页他没有生效是吗?没生效它也会执行
select count(0) from table
吗?
你的意思是我的分页他没有生效是吗?没生效它也会执行select count(0) from table吗?
在 2023-07-20 13:58:59,"Liuzh" @.***> 写道:
如果pagehelper分页插件起作用,返回的List实际类型一定是Page。
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
如果pagehelper分页插件起作用,返回的List实际类型一定是Page。
我大概知道了,是因为我从数据库查出来是DTO,然后在封装响应体时把DTO转换成了VO,导致这个list不是原来那个list
牛。已经选择从var page = PageHelper.startPage()中获取总条数了
问题描述
我在使用offset分页时,total不准确,total只会返回我查询到的数量,而不是在执行
select count(0) from table
返回的数量使用环境
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@443a37b0] will not be managed by Spring ==> Preparing: SELECT count(0) FROM t_community_video_comment tcvc WHERE video_id = ? AND tcvc.level = 1 ==> Parameters: 27896(Integer) <== Columns: count(0) <== Row: 3 <== Total: 1 ==> Preparing: SELECT tcvc.*, (SELECT count(id) FROM t_community_video_comment WHERE super_comment_id = tcvc.id) reply_count FROM t_community_video_comment tcvc WHERE video_id = ? AND tcvc.level = 1 order by create_time asc LIMIT ? ==> Parameters: 27896(Integer), 2(Integer) <== Columns: id, level, parent_comment_id, super_comment_id, video_id, user_id, nick_name, content, approve_status, is_deleted, create_by, create_time, update_by, update_time, reply_count <== Row: 1, 1, null, null, 27896, 1, 管理员, 我是一级评论, null, 0, admin, 2023-07-15 17:34:43, null, null, 3 <== Row: 2, 1, null, null, 27896, 2, 游客2, 我也是一级评论, null, 0, admin, 2023-07-15 17:35:13, null, null, 0 <== Total: 2 Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6b376ae7]