分頁的實現

2021-09-01 09:23:22 字數 1930 閱讀 4686

首先我們需要清楚的是,前台有後台的

/** * (這個分頁的功能)前端要想後台請求的引數為:

* page;當前頁

* rows:m每頁大小

* sortby:排序字段

* desc:是否為降序

* key:查詢的關鍵

* * 後台要想前台響應的話,我們就需要有響應的結果即可

* total:總條數

* items:當前頁資料

* totalpage:有些還需要總頁數。

* @param */

public class pageresult

public pageresult(long total, listitems)

public pageresult(long total, long totalpage, listitems)

public long gettotal()

public void settotal(long total)

public listgetitems()

public void setitems(listitems)

public long gettotalpage()

public void settotalpage(long totalpage)

}

@autowired

private brandservice brandservice;

/** * 後台向前臺請求的三個引數(當前頁資料,總條數,總頁數)

* @param page(當前頁) 每頁大小(rows)sortby(排序字段) desc(是否為降序) key(關鍵字)

* @return total(int 總條數) items(list當前頁資料) totalpage(int 總頁數)

*///前台我們根據url找到這個action。然後根據這些引數,最後我們返回給前台三個引數即可(將其封裝到了乙個物件裡面)

public responseentity querybrandbypage(

@requestparam(value = "page", defaultvalue = "1") integer page,

@requestparam(value = "rows", defaultvalue = "5") integer rows,

@requestparam(value = "sortby", required = false) string sortby,

@requestparam(value = "desc", defaultvalue = "false") boolean desc,

@requestparam(value = "key", required = false) string key)

return responseentity.ok(result);

}

@autowired

public pageresult

querybrandbypageandsort(

integer page, integer rows, string sortby, boolean desc, string key)

// 查詢

if (stringutils.isnotblank(key))

// 查詢

// for (brand brand:list)

pageinfo

pageinfo = new pageinfo<>(list);

"這裡我們輸出的總條數為"+pageinfo.gettotal());

// 返回結果

return new pageresult<>(pageinfo.gettotal(), pageinfo.getlist());

}

分頁的實現

分頁分為前端分頁和後端分頁,一下是兩者是簡單實現 1.前端分頁 前端分頁一般用jquery外掛程式來實現,一般原理如下 a.totalpage總頁數 b.totalcount符合條件的總記錄數 c.pagesize每頁顯示有多少 d.currentpage 當前第幾頁 e.pagestart 起始頁...

分頁的實現,

class page this url script implode p page this first this getfirst this last this getlast this prev this getprev this next this getnext private functi...

mysql實現分頁 MySQL如何實現分頁查詢

mysql中實現分頁查詢 在資料量較小的情況下可使用limit查詢來實現分頁查詢,在資料量大的情況下使用建立主鍵或唯一索引來實現,另外可通過order by對其排序 一般情況下在mysql中進行分頁查詢時,會用到limit查詢,而且在查詢中都會使用到order by來進行排序。接下來將具體介紹mys...