-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathPage.java
More file actions
69 lines (58 loc) · 1.67 KB
/
Page.java
File metadata and controls
69 lines (58 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package io.github.talelin.latticy.common.mybatis;
/**
* 分页对象
* 为和其他端保持一致
* 重写 MyBatis-Plus 分页对象,将起始页从 1 改为 0
*
* @author Juzi@TaleLin
*/
public class Page<T> extends com.baomidou.mybatisplus.extension.plugins.pagination.Page<T> {
private static final long serialVersionUID = -2183463672525305273L;
/**
* 该构造方法使得 current 总为 0
*/
public Page() {
super.setCurrent(0);
}
public Page(int current, int size) {
this(current, size, 0);
}
public Page(int current, int size, int total) {
this(current, size, total, true);
}
public Page(int current, int size, boolean isSearchCount) {
this(current, size, 0, isSearchCount);
}
/**
* 该构造方法将小于 0 的 current 置为 0
*
* @param current 当前页
* @param size 每页显示条数,默认 10
* @param total 总数
* @param isSearchCount 是否进行 count 查询
*/
public Page(int current, int size, int total, boolean isSearchCount) {
super(current, size, total, isSearchCount);
if (current < 0) {
current = 0;
}
super.setCurrent(current);
}
@Override
public boolean hasPrevious() {
return super.getCurrent() > 0;
}
@Override
public boolean hasNext() {
return super.getCurrent() + 1 < this.getPages();
}
/**
* 重写计算偏移量,将分页从第 0 开始
*
* @return 偏移量
*/
@Override
public long offset() {
return getCurrent() > 0 ? super.getCurrent() * getSize() : 0;
}
}