liurunyu
2024-04-15 55d5046ae0a9da1109e402d7d719f765a4bccdae
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
package com.dy.common.webUtil;
 
 
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.*;
 
import java.util.Map;
 
@Data
@ToString
public class QueryResultVo<T> {
 
    /**
     * 每页显示的记录数
     */
    public Integer pageSize ;
    /**
     * 记录总数
     */
    public Long itemTotal ;
    /**
     * 当前页
     */
    public Integer pageCurr ;
    /**
     * 总页数
     */
    public Integer pageTotal ;
 
    /**
     * 数据
     */
    public T obj;
 
    /**
     * 查询开始记录
     */
    @JSONField(serialize = false)
    public Integer queryStart ;
 
    /**
     * 查询数量
     */
    @JSONField(serialize = false)
    public Integer queryCount ;
 
    public QueryResultVo(Integer pageSize, Integer pageCurr){
        this.pageSize = pageSize ;
        this.pageCurr = pageCurr ;
    }
    /**
     * 进行计算
     * @param itemTotal
     * @param params
     */
    public void calculateAndSet(Long itemTotal, Map<String, Object> params) {
        this.itemTotal = itemTotal ;
        if(this.itemTotal == null){
            this.itemTotal = 0L ;
        }
 
        if(this.itemTotal == 0){
            this.pageSize = 1 ;
        }
        if(this.pageSize == null || this.pageSize <= 0){
            /**
             * 朱宝民 2024-01-30 修改
             * 未传入分页参数时,取全部记录
             */
            //this.pageSize = 1 ;//供下面作为除数
            this.pageSize = 10000 ;//供下面作为除数
        }
 
        pageTotal = (int)Math.ceil((itemTotal==null?0.0D:itemTotal.doubleValue())/pageSize);
 
        if (pageTotal == 0) {
            pageTotal = 1;
        }
        if (pageCurr == null || pageCurr < 1) {
            pageCurr = 1;
        }
        if (pageCurr > pageTotal) {
            pageCurr = pageTotal;
        }
 
        //select * from table_name limit 5 ,10;//从第6行开始,检索10行记录,即:检索记录行 6-15
        this.queryStart = (this.pageCurr - 1) * this.pageSize ;
        this.queryCount = this.pageSize ;
 
        params.put("start", this.queryStart) ;
        params.put("count", this.queryCount) ;
    }
 
}