文章來源:http://gf.johng.cn/597431javascript
分頁管理由gpage
包實現,gpage提供了強大的動態分頁及靜態分頁功能,而且爲開發者自定義分頁樣式提供了極高的靈活度。java
使用方式:git
import "gitee.com/johng/gf/g/util/gpage"
方法列表:godoc.org/github.com/johng-cn/gf/g/util/gpagegithub
func New(TotalSize, perPage int, CurrentPage interface{}, url string, route ...string) *Page func (page *Page) EnableAjax(actionName string) func (page *Page) FirstPage(styles ...string) string func (page *Page) GetContent(mode int) string func (page *Page) GetLink(url, text, title, style string) string func (page *Page) GetUrl(pageNo int) string func (page *Page) LastPage(styles ...string) string func (page *Page) NextPage(styles ...string) string func (page *Page) PageBar(styles ...string) string func (page *Page) PrevPage(styles ...string) string func (page *Page) SelectBar() string
咱們這裏須要着重說明的是三個方法,New
,GetContent
,EnableAjax
。後端
在New
方法中,前面三個參數很簡單,見名知意。url
第四個參數url string
是當前請求頁面的URL,能夠是完整的URL地址,如:http://xxx.xxx.xxx/list?type=10#anchor
;也能夠是URI絕對路徑地址,如:/list?type=10#anchor
;該參數是用於分頁管理器計算分頁URL地址的基礎。code
第五個參數route...string
是一個可選參數,表示當前請求頁面的路由匹配規則(如:/user/list/:page
,或者/order/list/*order-page
),當使用靜態分頁時,該參數爲必傳項,以便分頁管理器可以智能替換靜態URI中對應的分頁參數。對象
具體使用示例請查看後續章節。ip
方法GetContent
提供了預約義的常見的分頁樣式,以便於開發者快速使用。當預約義的樣式沒法知足開發者需求時,開發者能夠使用公開的方法來自定義分頁樣式(或者進行方法重載來實現自定義),也能夠使用正則替換指定預約義的分頁樣式中的部份內容來實現自定義。路由
具體使用示例請查看後續章節。
方法EnableAjax
給定一個Ajax方法名,用於實現Ajax分頁,可是須要注意的是,該Ajax方法名稱須要先後端約定統一,而且該Ajax方法只有一個URL參數。如下是一個Ajax方法的客戶端定義示例:
function DoAjax(url) { // 這裏讀取URL的內容並根據業務邏輯進行內容展現 }
具體使用示例請查看後續章節。