动态分页是通过GET参数(通过QueryString)传递分页参数,默认分页参数为page

    示例如下:

    1. package main
    2. import (
    3. "github.com/gogf/gf/frame/g"
    4. "github.com/gogf/gf/os/gview"
    5. "github.com/gogf/gf/net/ghttp"
    6. "github.com/gogf/gf/util/gpage"
    7. )
    8. func main() {
    9. s := ghttp.GetServer()
    10. s.BindHandler("/page/demo", func(r *ghttp.Request) {
    11. page := gpage.New(100, 10, r.Get("page"), r.URL.String())
    12. buffer, _ := gview.ParseContent(`
    13. <html>
    14. <head>
    15. <style>
    16. a,span {padding:8px; font-size:16px;}
    17. div{margin:5px 5px 20px 5px}
    18. </style>
    19. </head>
    20. <body>
    21. <div>{{.page1}}</div>
    22. <div>{{.page2}}</div>
    23. <div>{{.page3}}</div>
    24. <div>{{.page4}}</div>
    25. </body>
    26. </html>
    27. `, g.Map{
    28. "page1" : page.GetContent(1),
    29. "page2" : page.GetContent(2),
    30. "page3" : page.GetContent(3),
    31. "page4" : page.GetContent(4),
    32. })
    33. r.Response.Write(buffer)
    34. })
    35. s.SetPort(8199)
    36. s.Run()
    37. }

    该示例中,我们展示了四种预定义的分页样式,并通过GET方式进行分页传参。执行后,输出的内容如下图所示:

    动态分页 - 图1