導航:首頁 > 編程語言 > java分頁技術實現視頻教程

java分頁技術實現視頻教程

發布時間:2025-02-07 05:41:28

㈠ 怎樣用java實現分頁顯示

實現原理很簡單,就是建立一個Page類,裡面放當前訪問的頁數(這個是從客戶瀏覽器傳到後台的數據,所以你的分頁需要用它來定位記錄的條目)和每一頁顯示的記錄行數。然後通過分頁計算就可以得出下列數據。
(假定你的頁數從1開始)
1、總頁數 = 總記錄數/每頁大小,如果0!=總記錄數%每頁大小,那麼總頁數再+1
2、當前頁數(從瀏覽器傳遞的參數中獲得)
3、表記錄的起始位置=(當前頁數-1)*每頁大小
4、總記錄數(select count(*) from [表名] [where [條件]],從資料庫中查詢得到)
5、每頁大小,可以固定,也可以從頁面傳過來

有了這幾個參數之後,就用sql語句查出對應的記錄就可以了。
mysql資料庫用limit 表記錄的起始位置,每頁大小 語句添加到你的查詢語句最後面
sqlserver資料庫用top語句和not in 來做
oracle資料庫用rownum來做

再給你一段分頁對象代碼,你自己先讀一下

publicclassPage{

privatelongtotalCount=0;//總記錄數
privateintpageNumber=1;//當前頁號,默認顯示第一頁
privateintpageSize=20;//每頁大小,默認每頁20條
privateinttotalPage=0;//總頁數,默認為0
privateintstartRow=0;//起始記錄行號,默認為從表頭開始

/**
*分頁計算方法,由setTotalCount調用
*/
publicvoidpagination(){
//計算總頁數
if(this.totalCount%pageSize==0)
this.totalPage=newLong(this.totalCount/pageSize).intValue();
else
this.totalPage=newLong(this.totalCount/pageSize).intValue()+1;
//排除錯誤頁號
if(this.pageNumber<1)
this.pageNumber=1;
if(this.pageNumber>this.totalPage)
this.pageNumber=this.totalPage;
//計算起始行號
this.startRow=(this.pageNumber-1)*this.pageSize;
}

publiclonggetTotalCount(){
returntotalCount;
}

publicvoidsetTotalCount(longtotalCount){
this.totalCount=totalCount;
this.pagination();
}

publicintgetPageNumber(){
returnpageNumber;
}

publicvoidsetPageNumber(intpageNumber){
this.pageNumber=pageNumber;
}

publicintgetPageSize(){
returnpageSize;
}

publicvoidsetPageSize(intpageSize){
this.pageSize=pageSize;
}

publicintgetTotalPage(){
returntotalPage;
}

publicvoidsetTotalPage(inttotalPage){
this.totalPage=totalPage;
}

publicintgetStartRow(){
returnstartRow;
}

publicvoidsetStartRow(intstartRow){
this.startRow=startRow;
}

}
閱讀全文

與java分頁技術實現視頻教程相關的資料

熱點內容
ug3d硬料開出怎麼編程 瀏覽:151
如何獲取文件Linux命令 瀏覽:981
大智慧軟體哪個版本最好 瀏覽:698
狼人殺自動主持app叫什麼 瀏覽:949
checkbox怎麼綁定資料庫 瀏覽:945
編程怎麼設置一分鍾開燈 瀏覽:754
如何把桌面文件發送到自己郵箱 瀏覽:498
校園網站怎麼看選修的課 瀏覽:59
大數據專業哪個最好 瀏覽:467
一個文件內容替換另一個文件 瀏覽:288
ios8最好的版本 瀏覽:400
錄屏決定文件大小的是什麼 瀏覽:322
數據用不了是哪裡壞掉了 瀏覽:310
百度網盤文件傳輸格式 瀏覽:455
蘋果系統txt文件 瀏覽:629
家裝網站怎麼設計 瀏覽:202
adc指令微程序 瀏覽:487
名片模板word 瀏覽:635
怎麼把文件夾上鎖 瀏覽:331
我不會英語怎麼編程 瀏覽:895

友情鏈接