2021与蓝度共同重构项目,服务端
liuhaonan
2022-02-28 316dce3b4de147fdf301ff4295f286da908deffb
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
97
package com.sandu.ximon.admin.utils;
 
import java.util.Collections;
import java.util.List;
public class ListPageUtil<T> {
   private List<T> data;
 
    /** 上一页 */
     private int lastPage;
 
    /** 当前页 */
    private int currentPage;
 
     /** 下一页 */
    private int nextPage;
 //
     /** 每页条数 */
    private int pageSize;
 
    /** 总页数 */
    private int totalPage;
 
    /** 总数据条数 */
     private int totalCount;
 
     public ListPageUtil(List<T> data,int currentPage,int pageSize) {
         if (data == null || data.isEmpty()) {
            throw new IllegalArgumentException("data must be not empty!");
         }
 
        this.data = data;
         this.pageSize = pageSize;
         this.currentPage = currentPage;
        this.totalCount = data.size();
        this.totalPage = (totalCount + pageSize - 1) / pageSize;
        this.lastPage = currentPage-1>1? currentPage-1:1;
        this.nextPage = currentPage>=totalPage? totalPage: currentPage + 1;
 
     }
 
    /**
     * 得到分页后的数据
      * @return 分页后结果
     */
 //    public List<T> getPagedLst() {
 //        int fromIndex = (nowPage - 1) * pageSize;
//        if (fromIndex >= data.size()) {
 //            return Collections.emptyList();//空数组
 //        }
 //        if(fromIndex<0){
 //            return Collections.emptyList();//空数组
 //        }
//        int toIndex = nowPage * pageSize;
//        if (toIndex >= data.size()) {
//            toIndex = data.size();
 //        }
 //        return data.subList(fromIndex, toIndex);
 //    }
 
     public int getPageSize() {
        return pageSize;
    }
 
      public List<T> getData() {
          int fromIndex = (currentPage - 1) * pageSize;
         if (fromIndex >= data.size()) {
             return Collections.emptyList();//空数组
        }
        if(fromIndex<0){
             return Collections.emptyList();//空数组
        }
         int toIndex = currentPage * pageSize;
         if (toIndex >= data.size()) {
             toIndex = data.size();
         }
        return data.subList(fromIndex, toIndex);
     }
     public int getLastPage() {
         return lastPage;
    }
 
     public int getCurrentPage() {
        return currentPage;
     }
 
     public int getNextPage() {
         return nextPage;
     }
 
    public int getTotalPage() {
        return totalPage;
     }
 
     public int getTotalCount() {
         return totalCount;
     }
 }