Skip to content

Commit 573e6aa

Browse files
juzi214032colorful3
authored andcommitted
fix(Page): 修复分页问题
Page 分页对象重写 offset() 方法。 修复分页指定为 1 时,却返回第 1 页数据的问题 (因起始页为0,正确的应该返回第 2 页的数据)
1 parent fc9b169 commit 573e6aa

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

  • src/main/java/io/github/talelin/latticy/common/mybatis

src/main/java/io/github/talelin/latticy/common/mybatis/Page.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ public Page(long current, long size, boolean isSearchCount) {
3131

3232
/**
3333
* 该构造方法将小于 0 的 current 置为 0
34-
* @param current 当前页
35-
* @param size 每页显示条数,默认 10
36-
* @param total 总数
34+
*
35+
* @param current 当前页
36+
* @param size 每页显示条数,默认 10
37+
* @param total 总数
3738
* @param isSearchCount 是否进行 count 查询
3839
*/
3940
public Page(long current, long size, long total, boolean isSearchCount) {
@@ -54,4 +55,14 @@ public boolean hasPrevious() {
5455
public boolean hasNext() {
5556
return super.getCurrent() + 1 < this.getPages();
5657
}
58+
59+
/**
60+
* 重写计算偏移量,将分页从第 0 开始
61+
*
62+
* @return 偏移量
63+
*/
64+
@Override
65+
public long offset() {
66+
return getCurrent() > 0 ? super.getCurrent() * getSize() : 0;
67+
}
5768
}

0 commit comments

Comments
 (0)