1 Star 0 Fork 0

tomatomeatman/GolangRepository

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Page.go 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
tomatomeatman 提交于 2025-06-10 14:51 +08:00 . 2
package dbinfo
// 分页数据信息对象,常用于前端与后台列表数据交互
type Page struct {
Current int `json:"current"` //当前页
Size int `json:"size"` //每页显示记录
CountRow int `json:"countRow"` //总记录数
CountPage int `json:"countPage"` //总页数
Record []map[string]interface{} `json:"record"` //本页的数据列表
}
// 创建分页信息
func (Page) New() *Page {
result := Page{}
result.Current = 1
result.Size = 10
result.CountRow = 0
result.CountPage = 0
return &result
}
// 设置分页信息
func (p *Page) Set(start, size, countRow int, record []map[string]interface{}) *Page {
if start < 1 {
start = 0
}
if size < 1 {
size = 10
}
if countRow < 0 {
countRow = 0
}
current := start / size
countPage := 1
if (countRow > 0) && (size > 0) {
if countRow%size == 0 {
countPage = countRow / size
} else {
countPage = countRow/size + 1
}
}
p.Current = current
p.Size = size
p.CountRow = countRow
p.CountPage = countPage
p.Record = record
return p
}
// 设置数据列表
func (p *Page) SetRecord(record []map[string]interface{}) *Page {
p.Record = record
return p
}
/**
* 将map数据转换为分页信息
* @param data
* @return
*/
func MapToPage(data map[string]interface{}) *Page {
result := Page{}.New()
if v, ok := data["current"]; ok {
temp := v.(int)
if temp > 0 {
result.Current = temp
}
}
if v, ok := data["size"]; ok {
temp := v.(int)
if temp > 0 {
result.Size = temp
}
}
return result
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tomatomeatman/golang-repository.git
git@gitee.com:tomatomeatman/golang-repository.git
tomatomeatman
golang-repository
GolangRepository
941dedad80c3

搜索帮助