获取所有文章数据

o := orm.NewOrm()
qs := o.QueryTable("Article")
12

获取总条数

count, _ := qs.Count()
1

设置每页的条数

pageSetNum := 2
1

总页数和当前页码

//	总页数
pageCount := math.Ceil((float64(count) / float64(pageSetNum)))
//	获取当前页码
pageNum, err := this.GetInt("pageNum")
if err != nil {
	pageNum = 1
}
1234567

获取分页数据

//存储分页数据的切片
articles := new([]models.Article)
//获取分页数据
qs.Limit(pageSetNum, pageSetNum*(pageNum - 1)).All(articles)
1234

返回数据

beego.Info(*articles)
this.Data["articles"] = *articles
this.Data["count"] = count
this.Data["pageCount"] = pageCount
this.Data["pageNum"] = pageNum
this.TplName = "index.html"

相关文章:

  • 2022-12-23
  • 2021-09-30
  • 2021-12-12
  • 2021-12-26
  • 2021-12-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-08-22
相关资源
相似解决方案