ソースを参照

分页返回总页数

zhangjq 6 年 前
コミット
a686810e86
3 ファイル変更11 行追加8 行削除
  1. 2 1
      light-apiengine.xml
  2. 3 1
      models/PageResult_gen.go
  3. 6 6
      utils/page_util.go

+ 2 - 1
light-apiengine.xml

@@ -315,7 +315,8 @@
         <bean name="page_result" desc="分页结果">
             <prop name="page" caption="页码" type="int" />
             <prop name="rows" caption="单页数" type="int" />
-            <prop name="totalSize" caption="总页数" type="int64" />
+            <prop name="totalSize" caption="总数" type="int64" />
+            <prop name="totalPageSize" caption="总页数" type="int64"/>
             <prop name="content" caption="内容" type="interface{}" />
         </bean>
         <bean name="tree_node" desc="树结点">

+ 3 - 1
models/PageResult_gen.go

@@ -12,8 +12,10 @@ type PageResult struct {
 	Page   int `json:"page"`
 	//单页数
 	Rows   int `json:"rows"`
-	//总
+	//总数
 	TotalSize   int64 `json:"totalSize"`
+	//总页数
+	TotalPageSize   int64 `json:"totalPageSize"`
 	//内容
 	Content   interface{} `json:"content"`
 

+ 6 - 6
utils/page_util.go

@@ -29,13 +29,13 @@ func PageSearch(engine *xorm.Engine, controllername string, apiname string, tabl
 	}
 	records := cresult[0]["records"].(int64)
 
-	var totalSize int64 = 0
-	if totalSize < int64(rows) {
-		totalSize = 1
+	var totalPageSize int64 = 0
+	if totalPageSize < int64(rows) {
+		totalPageSize = 1
 	} else if records%int64(rows) == 0 {
-		totalSize = records / int64(rows)
+		totalPageSize = records / int64(rows)
 	} else {
-		totalSize = records / int64(rows+1)
+		totalPageSize = records / int64(rows+1)
 	}
 
 	presult := models.PageResult{}
@@ -43,6 +43,6 @@ func PageSearch(engine *xorm.Engine, controllername string, apiname string, tabl
 	presult.Rows = (rows)
 	presult.Content = result
 	presult.TotalSize = records
-
+	presult.TotalPageSize = totalPageSize
 	return &presult, nil
 }