派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.qxueyou.scc.base.model;
 
public class Pager {
    
    /*
     * 每页显示条数
     */
    private int pageSize;
    
    /*
     * 当前页码
     */
    private int pageNum;
    
    /*
     * 记录总数
     */
    private int totalCount;
    
    public Pager(){
        //constructor
    }
    
    public Pager(int pageSize,int pageNum){
        this.pageSize=pageSize;
        this.pageNum=pageNum;
    }
    
    public int getPageSize() {
        return pageSize <= 0?Integer.MAX_VALUE:pageSize;
    }
 
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
 
    public int getPageNum() {
        return pageNum <= 0?1:pageNum;
    }
    
    public int getOffset() {
        return pageNum <= 1?0:(pageNum-1)*this.getPageSize();
    }
 
    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }
 
    public int getTotalCount() {
        return totalCount;
    }
 
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }
 
    /**
     * 计算总页数
     * @return
     */
    public int getPageCount(){
        return totalCount%pageSize>0?totalCount/pageSize+1:totalCount/pageSize;
    }
    
    /**
     * 计算分页栏起始页
     * @return
     */
    public int getPageDispayStart(){
 
        int startGap = Math.min(pageNum-1,2);
        int endGap = Math.min(getPageCount()-pageNum,2);
        
        if(startGap<=endGap){
            return Math.max(pageNum-startGap,1);
        }else{
            return Math.max(pageNum-(4-endGap),1);
        }
        
    }
    
    /**
     * 计算分页栏结束页
     * @return
     */
    public int getPageDispayEnd(){
        int startGap = Math.min(pageNum-1,2);
        int endGap = Math.min(getPageCount()-pageNum,2);
        
        if(startGap<=endGap){
            return Math.min(pageNum+(4-startGap),getPageCount());
        }else{
            return Math.min(pageNum+endGap,getPageCount());
        }
    }
}