1234567891011121314151617181920 |
- package common
- import (
- "confrontation-training/global"
- "confrontation-training/models"
- )
- // RestPage
- //page 设置起始页,每页记录数
- //name 查询目标表的名称
- //query 查询条件
- //dest 查询结果绑定的结构体
- //bind 绑定表结构对应的结构体
- func RestPage(page models.Page, tableName string, query interface{}, orderBy string, dest interface{}, bind interface{}) int64 {
- if page.PageNum > 0 && page.PageSize > 0 {
- offset := (page.PageNum - 1) * page.PageSize
- global.Db.Debug().Offset(offset).Limit(page.PageSize).Table(tableName).Where(query).Order(orderBy).Find(dest)
- }
- return global.Db.Debug().Table(tableName).Where(query).Order(orderBy).Find(bind).RowsAffected
- }
|