page.go 711 B

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