Java實現簡單的分頁效果

2021-09-11 02:35:33 字數 1502 閱讀 8959

實現分頁功能,在查詢的時候我們需要多少條資料就查詢多少條資料。具體如下:

首先我們定義乙個pagebean的實體類,類中有如下屬性

public class pagebean 

public pagebean()

public int gettotalcount()

public void settotalcount(int totalcount)

public int gettotalpage()

public int getrows()

public void setrows(int rows)

public int getcurrentpage()

public void setcurrentpage(int currentpage)

public listgetlist()

public void setlist(listlist)

}

servlet層:獲取當前頁,呼叫service.getpagebean()傳入每頁條數和當前頁面

studentservice service =  new studentserviceimpl();

response.setcontenttype("text/html;charset=utf-8");

string currentpage = request.getparameter("currentpage");

if(currentpage == null)

pagebean pagebean = service.getpagebean(3, integer.parseint(currentpage));

request.getsession().setattribute("pb", pagebean);

response.sendredirect("/index.jsp");

service層

public pagebean getpagebean(int rows, int currentpage)
dao層

1、獲取總條數

public int gettotalcount()  catch (sqlexception e) 

return row;

}

2、分頁

public listgetstudentsbypage(int rows, int currentpage) 

jdbcutils.close(ps, connection);

} catch (sqlexception e)

return list;

}

前台頁面展示

編號

姓名性別

年齡操作

$$$$

這樣乙個簡單的分頁效果就實現了。

AJAX分頁效果簡單實現

最近寫乙個給使用者組新增角色的功能,要求一邊是未新增的角色,一邊是已新增的角色,還有搜尋功能,點選新增後,ajax儲存操作.考慮功能為待查詢功能分頁 下方分頁條,一共有 2 2 4個ajax js 如下 document ready function 當前角色列表 function currentr...

vue專案中實現簡單的分頁效果

vue專案中實現簡單的分頁效果 1.在data中宣告資料 data totalpage 1,總頁碼數,預設為1 currentpage 1,當前頁,預設第一頁,pagesize 3,每頁顯示的數量 currentpagedata 當前頁顯示的內容 productlist 資料總條數 template...

java簡單分頁

1.在顯示列表頁加上如下 teachplanlist是後台設定的乙個屬性,前台獲取這個屬性並取值 list list list request.getattribute teachplanlist int number list.size 以下這段 是計算多少頁數 int pagenumber nu...