添加分页

This commit is contained in:
baichou
2022-06-16 19:08:31 +08:00
parent 43b82e30ea
commit 7a2b29bba0
2 changed files with 11 additions and 1 deletions

View File

@@ -176,6 +176,11 @@ func (orm *OrmMysqlTableName) Paginate(page int, limit int) (MysqlTableNameList,
list := make([]*MysqlTableName, 0)
orm.db.Count(&total)
if total > 0 {
if page == 0 {
page = 1
}
offset := (page - 1) * limit
tx := orm.db.Offset(page).Limit(limit).Find(&list)
if tx.Error != nil {
logrus.Error(tx.Error)

View File

@@ -176,7 +176,12 @@ func (orm *Orm{orm_table_name}) Paginate(page int, limit int) ({orm_table_name}L
list := make([]*{orm_table_name}, 0)
orm.db.Count(&total)
if total > 0 {
tx := orm.db.Offset(page).Limit(limit).Find(&list)
if page == 0 {
page = 1
}
offset := (page - 1) * limit
tx := orm.db.Offset(offset).Limit(limit).Find(&list)
if tx.Error != nil {
logrus.Error(tx.Error)
}