-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPage.go
81 lines (70 loc) · 2.21 KB
/
Page.go
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
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package zorm
// Page 分页对象
// Page Pagination object
type Page struct {
// 当前页码,从1开始
// Current page number, starting from 1
PageNo int `json:"pageNo,omitempty"`
// 每页多少条,默认20条
// How many items per page, 20 items by default
PageSize int `json:"pageSize,omitempty"`
// 数据总条数
// Total number of data
TotalCount int `json:"totalCount,omitempty"`
// 共多少页
// How many pages
PageCount int `json:"pageCount,omitempty"`
// 是否是第一页
// Is it the first page
FirstPage bool `json:"firstPage,omitempty"`
// 是否有上一页
// Whether there is a previous page
HasPrev bool `json:"hasPrev,omitempty"`
// 是否有下一页
// Is there a next page
HasNext bool `json:"hasNext,omitempty"`
// 是否是最后一页
// Is it the last page
LastPage bool `json:"lastPage,omitempty"`
}
// NewPage 创建Page对象
// NewPage Create Page object
func NewPage() *Page {
page := Page{}
page.PageNo = 1
page.PageSize = 20
return &page
}
// setTotalCount 设置总条数,计算其他值
// setTotalCount Set the total number of bars, calculate other values
func (page *Page) setTotalCount(total int) {
page.TotalCount = total
page.PageCount = (page.TotalCount + page.PageSize - 1) / page.PageSize
if page.PageNo >= page.PageCount {
page.LastPage = true
} else {
page.HasNext = true
}
if page.PageNo > 1 {
page.HasPrev = true
} else {
page.FirstPage = true
}
}