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
package com.dy.common.webUtil;
 
 
import com.alibaba.fastjson2.annotation.JSONField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
 
import java.util.Map;
 
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Schema(name = "查询结果基类")
public class QueryResultVo<T> {
 
    /**
     * 每页显示的记录数
     */
    @Schema(description = "每页记录数")
    @Builder.Default
    public Integer pageSize = 0 ;
    /**
     * 记录总数
     */
    @Schema(description = "记录总数")
    @Builder.Default
    public Long itemTotal = 0L;
    /**
     * 当前页
     */
    @Schema(description = "当前页")
    @Builder.Default
    public Integer pageCurr = 0;
    /**
     * 总页数
     */
    @Schema(description = "总页数")
    @Builder.Default
    public Integer pageTotal = 0;
 
    @Schema(description = "数据")
    @Builder.Default
    public T content = null;
 
    /**
     * 查询开始记录
     */
    @Schema(hidden = true)
    @JSONField(serialize = false)
    public Integer queryStart ;
 
    /**
     * 查询数量
     */
    @Schema(hidden = true)
    @JSONField(serialize = false)
    public Integer queryCount ;
 
 
    public void calculateAndSet(Long itemTotal, Map<String, Object> params) {
        this.itemTotal = itemTotal ;
        if(this.itemTotal == null){
            itemTotal = 0L ;
        }
 
        if (pageSize < 1) {
            pageSize = 1;
        }
        pageTotal = (int)Math.ceil((double)itemTotal/pageSize);
 
        if (pageTotal == 0) {
            pageTotal = 1;
        }
        if (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("queryStart", this.queryStart) ;
        params.put("queryCount", this.queryCount) ;
    }
 
}