gpage supports custom URL templates, where the {.page} built-in variable can be used to replace the content of the page number. Let’s look at a simple example:

    1. package main
    2. import (
    3. "github.com/gogf/gf/v2/frame/g"
    4. "github.com/gogf/gf/v2/net/ghttp"
    5. "github.com/gogf/gf/v2/os/gview"
    6. )
    7. func main() {
    8. s := g.Server()
    9. s.BindHandler("/page/template/{page}.html", func(r *ghttp.Request) {
    10. page := r.GetPage(100, 10)
    11. page.UrlTemplate = "/order/list/{.page}.html"
    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. }

    In the code, we can set the URL template using the UrlTemplate property. After executing, the result is as follows:

    Pagination - URL Template - 图1