Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PageHelper.offsetPage使用,预期结果只有1条,count为true或false,结果返回不一致。 #773

Open
zsj-up opened this issue Oct 9, 2023 · 5 comments
Labels

Comments

@zsj-up
Copy link

zsj-up commented Oct 9, 2023

  • [ √] 我已在 issues 搜索类似问题,并且不存在相同的问题.

异常模板

数据库中有4条数据,
PageHelper.offsetPage(3, 4, true) 返回结果是数据库中的全部4条;
PageHelper.offsetPage(3, 4, false) 返回结果是数据库中的最后1条,和预期一致;

但是
PageHelper.offsetPage(2, 4, true);
PageHelper.offsetPage(2, 4, false);
返回结果都是数据库中的最后2条.

使用环境

  • PageHelper 版本: 5.3.1
  • 数据库类型和版本: MySql 5.6

SQL 解析错误

分页参数

PageHelper.offsetPage(3, 4true); 
xxxMapper.selectByExample(criteria)

原 SQL

select * from xxx where xxx = xxx limit 0,4

期望的结果:

select * from xxx where xxx = xxx limit 3, 4

其他类型的错误

功能建议

count为true或false时结果应一致。

@abel533 abel533 added the bug label Oct 9, 2023
@pagehelper
Copy link
Owner

测试发现count为true,false不影响分页sql,没有问题。

PageHelper.offsetPage(3, 4, true); 参数对应的 hsql分页测试的SQL:

23:07:16.377 [main] DEBUG c.g.p.mapper.UserMapper.selectAll - ==>  Preparing: select * from user order by id -- comment LIMIT ? OFFSET ?
23:07:16.381 [main] DEBUG c.g.p.mapper.UserMapper.selectAll - ==> Parameters: 4(Integer), 3(Long)
23:07:16.383 [main] TRACE c.g.p.mapper.UserMapper.selectAll - <==    Columns: ID, NAME, PY
23:07:16.384 [main] TRACE c.g.p.mapper.UserMapper.selectAll - <==        Row: 4, 常元琴, CYQ
23:07:16.390 [main] DEBUG c.g.p.mapper.UserMapper.selectAll - <==      Total: 1

PageHelper.offsetPage(2, 4, true); 参数对应的 hsql分页测试的SQL:

23:07:21.507 [main] DEBUG c.g.p.mapper.UserMapper.selectAll - ==>  Preparing: select * from user order by id -- comment LIMIT ? OFFSET ?
23:07:21.508 [main] DEBUG c.g.p.mapper.UserMapper.selectAll - ==> Parameters: 4(Integer), 2(Long)
23:07:21.510 [main] TRACE c.g.p.mapper.UserMapper.selectAll - <==    Columns: ID, NAME, PY
23:07:21.510 [main] TRACE c.g.p.mapper.UserMapper.selectAll - <==        Row: 3, 曾三杰, ZSJ
23:07:21.511 [main] TRACE c.g.p.mapper.UserMapper.selectAll - <==        Row: 4, 常元琴, CYQ
23:07:21.512 [main] DEBUG c.g.p.mapper.UserMapper.selectAll - <==      Total: 2

@zsj-up
Copy link
Author

zsj-up commented Nov 1, 2023

这两个例子都是count为true的呀?

@abel533
Copy link
Collaborator

abel533 commented Nov 2, 2023

false也测试了,和true的结果一样。。我找时间再试试mysql。

@abel533 abel533 reopened this Nov 2, 2023
@QingFengYunYing
Copy link

PageHelper 版本: 5.3.1
oracle19c
遇到问题一样情况

@QingFengYunYing
Copy link

PageHelper 版本: 5.3.1 oracle19c 遇到问题一样情况
PageHelper.offsetPage(16,10)
分析后发现:reasonable = true 导致
1)获取count后,会setTotal, reasonable = true 时会重置startRow,endRow,导致结果不一致

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants