Bladeren bron

fix: page_util

double 5 jaren geleden
bovenliggende
commit
c5b3656e05
1 gewijzigde bestanden met toevoegingen van 6 en 2 verwijderingen
  1. 6 2
      utils/page_util.go

+ 6 - 2
utils/page_util.go

@@ -2,6 +2,7 @@ package utils
 
 import (
 	"fmt"
+
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/models"
 	"github.com/xormplus/xorm"
 )
@@ -40,7 +41,10 @@ func PageSearch(engine *xorm.Engine, controllername string, apiname string, tabl
 		return &presult, nil
 	}
 
-	records := cresult[0]["records"].(int64)
+	records := 0
+	if cresult != nil && len(cresult) > 0 {
+		records = cresult[0]["records"].(int64)
+	}
 
 	var totalPageSize int64 = 0
 	if records < int64(rows) {
@@ -48,7 +52,7 @@ func PageSearch(engine *xorm.Engine, controllername string, apiname string, tabl
 	} else if records%int64(rows) == 0 {
 		totalPageSize = records / int64(rows)
 	} else {
-		totalPageSize = records / int64(rows) + 1
+		totalPageSize = records/int64(rows) + 1
 	}
 
 	presult := models.PageResult{}