整理
This commit is contained in:
25
utils/pagination.go
Normal file
25
utils/pagination.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Pager struct {
|
||||
Page int `json:"page" form:"page"`
|
||||
PageSize int `json:"pageSize" form:"pageSize"`
|
||||
OffSet int `json:"-"`
|
||||
Total int `json:"total"`
|
||||
MaxPage int `json:"maxPage"`
|
||||
}
|
||||
|
||||
func (p *Pager) InitPager(ctx *gin.Context) {
|
||||
p.Page, _ = strconv.Atoi(ctx.DefaultQuery("page", "1"))
|
||||
p.PageSize, _ = strconv.Atoi(ctx.DefaultQuery("pageSize", "10"))
|
||||
p.OffSet = (p.Page - 1) * p.PageSize
|
||||
}
|
||||
|
||||
func (p *Pager) GetPager() {
|
||||
p.MaxPage = int(p.Total/p.PageSize) + 1
|
||||
}
|
||||
Reference in New Issue
Block a user