import java.sql.Connection;
創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供安國(guó)網(wǎng)站建設(shè)、安國(guó)做網(wǎng)站、安國(guó)網(wǎng)站設(shè)計(jì)、安國(guó)網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、安國(guó)企業(yè)網(wǎng)站模板建站服務(wù),10余年安國(guó)做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import com.lqh.dao.db.DBCon;
public class PageDAO {
public static final String Text = "text";
public static final String Image = "image";
public static final String BbsText = "bbstext";
public static final String BbsImage = "bbsimage";
private HttpServletRequest request;
private int currentpage = 1; // 當(dāng)前是第幾頁(yè)
private int pagecount = 0; // 一共有多少頁(yè)
private int rscount = 0; // 一共有多少行
private int pagesize = 10; // 每頁(yè)有多少行[默認(rèn)為20行]
public PageDAO(HttpServletRequest request) {
this.request = request;
}
public int getCurrentpage() {
return currentpage;
}
public void setCurrentpage(int currentpage) {
this.currentpage = currentpage;
}
public int getPagecount() {
return pagecount;
}
public void setPagecount(int pagecount) {
this.pagecount = pagecount;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
public int getRscount() {
return rscount;
}
public void setRscount(int rscount) {
this.rscount = rscount;
}
/**
* 傳入SQL語(yǔ)句獲取總記錄數(shù)
*/
public int getRsCountForRs(String sql) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DBCon dbcon=new DBCon();
try {
conn = dbcon.getConn();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
rs.last();
this.rscount = rs.getRow();
} else {
this.rscount = 0;
}
} catch (Exception ex) {
ex.printStackTrace();
this.rscount = 0;
} finally {
dbcon.tryClose(rs, ps, conn);
}
return this.rscount;
}
public int getRsCountForSQL(String sql) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DBCon dbcon=new DBCon();
try {
conn = dbcon.getConn();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
this.rscount = rs.getInt("rscount");
} else {
this.rscount = 0;
}
} catch (Exception ex) {
ex.printStackTrace();
this.rscount = 0;
} finally {
dbcon.tryClose(rs, ps, conn);
}
return this.rscount;
}
/**
* 獲取總頁(yè)數(shù)
*
* @return int
*/
public int getPageCount() {
try {
this.pagecount = ((this.rscount - 1) / this.pagesize) + 1;
} catch (Exception ex) {
this.pagecount = 0;
}
return this.pagecount;
}
/**
* 獲取當(dāng)前頁(yè)碼的設(shè)置
*
* @return int
*/
public int getCurrentPage() {
try {
if (this.request.getParameter("currentpage") != null
Integer.parseInt(this.request
.getParameter("currentpage")) 1) {
this.currentpage = Integer.parseInt(this.request
.getParameter("currentpage"));
} else {
this.currentpage = 1;
}
} catch (Exception ex) {
this.currentpage = 1;
}
return this.currentpage;
}
/**
* 分頁(yè)工具條
*
* @param fileName
* String
* @return String
*/
public String pagetool(String flag) {
StringBuffer str = new StringBuffer();
String url = this.getParamUrl();
int ProPage = this.currentpage - 1;
int Nextpage = this.currentpage + 1;
// 文字的分頁(yè)
if (flag.equals(PageDAO.Text)) {
str.append("form method='post' name='pageform' action=''");
str
.append("table style='color: windowframe' width='100%' border='0' cellspacing='0' cellpadding='0'");
str.append("tr");
str.append("td width='20%'/td");
str.append("td height='26'");
str.append("共有記錄" + this.rscount + "條?");
str.append("共" + this.pagecount + "頁(yè)?");
str.append("每頁(yè)" + this.pagesize + "記錄?");
str.append("現(xiàn)在" + this.currentpage + "/" + this.pagecount + "頁(yè)");
str.append("/tdtd");
if (this.currentpage 1) {
str.append("a href='" + url + "currentpage=1'首頁(yè)/a");
str.append("?");
str.append("a href='" + url + "currentpage=" + ProPage
+ "'上一頁(yè)/a");
str.append("?");
} else {
str.append("首頁(yè)");
str.append("?");
str.append("上一頁(yè)");
str.append("?");
}
if (this.currentpage this.pagecount) {
str.append("a href='" + url + "currentpage=" + Nextpage
+ "'下一頁(yè)/a");
str.append("?");
} else {
str.append("下一頁(yè)");
str.append("?");
}
if (this.pagecount 1 this.currentpage != this.pagecount) {
str.append("a href='" + url + "currentpage=" + pagecount
+ "'尾頁(yè)/a");
str.append("?");
} else {
str.append("尾頁(yè)");
str.append("?");
}
str.append("轉(zhuǎn)到");
str
.append("select name='currentpage' onchange='javascript:ChangePage(this.value);'");
for (int j = 1; j = pagecount; j++) {
str.append("option value='" + j + "'");
if (currentpage == j) {
str.append("selected");
}
str.append("");
str.append("" + j + "");
str.append("/option");
}
str.append("/select頁(yè)");
str.append("/tdtd width='3%'?/td/tr/table");
str.append("script language='javascript'");
str.append("function ChangePage(testpage){");
str.append("document.pageform.action='" + url
+ "currentpage='+testpage+'';");
str.append("document.pageform.submit();");
str.append("}");
str.append("/script");
str.append("/form");
} else if (flag.equals(PageDAO.Image)) {
/**
* 圖片的分頁(yè)
*/
} else if (flag.equals(PageDAO.BbsText)) {
/**
* 論壇形式的分頁(yè)[直接以數(shù)字方式體現(xiàn)]
*/
str
.append("table width='100%' border='0' cellspacing='0' cellpadding='0'");
str.append("tr");
str.append("td width='3%'?/td");
str.append("td height='26'");
str.append("記錄" + this.rscount + "條??");
str.append("共" + this.pagecount + "頁(yè)??");
str.append("每頁(yè)" + this.pagesize + "記錄??");
str.append("現(xiàn)在" + this.currentpage + "/" + this.pagecount + "頁(yè)");
str.append("/tdtd");
// 設(shè)定是否有首頁(yè)的鏈接
if (this.currentpage 1) {
str.append("a href='" + url + "currentpage=1'首頁(yè)/a");
str.append("??");
}
// 設(shè)定是否有上一頁(yè)的鏈接
if (this.currentpage 1) {
str.append("a href='" + url + "currentpage=" + ProPage
+ "'上一頁(yè)/a");
str.append("???");
}
// 如果總頁(yè)數(shù)只有10的話
if (this.pagecount = 10) {
for (int i = 1; i = this.pagecount; i++) {
if (this.currentpage == i) {
str.append("font color=red[" + i
+ "]/font??");
} else {
str.append("a href='" + url + "currentpage=" + i
+ "'" + i + "/a??");
}
}
} else {
// 說明總數(shù)有超過10頁(yè)
// 制定特環(huán)的開始頁(yè)和結(jié)束頁(yè)
int endPage = this.currentpage + 4;
if (endPage this.pagecount) {
endPage = this.pagecount;
}
int startPage = 0;
if (this.pagecount = 8 this.currentpage = 8) {
startPage = this.currentpage - 5;
} else {
// 表示從第一頁(yè)開始算
startPage = 1;
}
System.out.println(startPage);
System.out.println(endPage);
for (int i = startPage; i = endPage; i++) {
if (this.currentpage == i) {
str.append("font color=red[" + i
+ "]/font??");
} else {
str.append("a href='" + url + "currentpage=" + i
+ "'" + i + "/a??");
}
}
}
// 設(shè)定是否有下一頁(yè)的鏈接
if (this.currentpage this.pagecount) {
str.append("a href='" + url + "currentpage=" + Nextpage
+ "'下一頁(yè)/a");
str.append("??");
}
// 設(shè)定是否有尾頁(yè)的鏈接
if (this.pagecount 1 this.currentpage != this.pagecount) {
str.append("a href='" + url + "currentpage=" + pagecount
+ "'尾頁(yè)/a");
str.append("??");
}
str.append("/tdtd width='3%'?/td/tr/table");
} else if (flag.equals(PageDAO.BbsImage)) {
/**
* 論壇形式的分頁(yè)[以圖片的方式體現(xiàn)]
*/
// 設(shè)定分頁(yè)顯示的CSS
str.append("style");
str
.append("BODY {FONT-SIZE: 12px;FONT-FAMILY:宋體;WIDTH: 60%; PADDING-LEFT: 25px;}");
str
.append("DIV.meneame {PADDING-RIGHT: 3px; PADDING-LEFT: 3px; FONT-SIZE: 80%; PADDING-BOTTOM: 3px; MARGIN: 3px; COLOR: #ff6500; PADDING-TOP: 3px; TEXT-ALIGN: center}");
str
.append("DIV.meneame A {BORDER-RIGHT: #ff9600 1px solid; PADDING-RIGHT: 7px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #ff9600 1px solid; PADDING-LEFT: 7px; BACKGROUND-IMAGE: url('"
+ this.request.getContextPath()
+ "/meneame.jpg'); PADDING-BOTTOM: 5px; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ff9600 1px solid; TEXT-DECORATION: none}");
str
.append("DIV.meneame A:hover {BORDER-RIGHT: #ff9600 1px solid; BORDER-TOP: #ff9600 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; BORDER-BOTTOM: #ff9600 1px solid; BACKGROUND-COLOR: #ffc794}");
str
.append("DIV.meneame SPAN.current {BORDER-RIGHT: #ff6500 1px solid; PADDING-RIGHT: 7px; BORDER-TOP: #ff6500 1px solid; PADDING-LEFT: 7px; FONT-WEIGHT: bold; PADDING-BOTTOM: 5px; BORDER-LEFT: #ff6500 1px solid; COLOR: #ff6500; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ff6500 1px solid; BACKGROUND-COLOR: #ffbe94}");
str
.append("DIV.meneame SPAN.disabled {BORDER-RIGHT: #ffe3c6 1px solid; PADDING-RIGHT: 7px; BORDER-TOP: #ffe3c6 1px solid; PADDING-LEFT: 7px; PADDING-BOTTOM: 5px; BORDER-LEFT: #ffe3c6 1px solid; COLOR: #ffe3c6; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ffe3c6 1px solid}");
str.append("/style");
str.append("div class=\"meneame\"");
// 判定是否有上一頁(yè)
if (this.currentpage 1) {
str.append("a href='" + url
+ "currentpage=1' hidefocus=\"true\"首頁(yè)/a");
str.append("???");
str.append("a href='" + url + "currentpage=" + ProPage
+ "' hidefocus=\"true\"上一頁(yè)/a");
str.append("???");
} else {
str.append("span class=\"disabled\"首頁(yè)/span");
str.append("??");
str.append("span class=\"disabled\"上一頁(yè)/span");
str.append("??");
}
// 顯示中間的圖片
if (this.pagecount = 10) {
for (int i = 1; i = this.pagecount; i++) {
if (this.currentpage == i) {
str.append("span class=\"current\"" + i + "/span");
} else {
str.append("a href='" + url + "currentpage=" + i
+ "' hidefocus=\"true\"" + i
+ "/a??");
}
}
} else {
// 說明總數(shù)有超過10頁(yè)
// 制定特環(huán)的開始頁(yè)和結(jié)束頁(yè)
int endPage = this.currentpage + 4;
if (endPage this.pagecount) {
endPage = this.pagecount;
}
int startPage = 0;
if (this.pagecount = 8 this.currentpage = 8) {
startPage = this.currentpage - 5;
} else {
// 表示從第一頁(yè)開始算
startPage = 1;
}
System.out.println(startPage);
System.out.println(endPage);
for (int i = startPage; i = endPage; i++) {
if (this.currentpage == i) {
str.append("span class=\"current\"" + i + "/span");
} else {
str.append("a href='" + url + "currentpage=" + i
+ "' hidefocus=\"true\"" + i
+ "/a??");
}
}
}
// 判斷下一頁(yè)和尾頁(yè)
if (this.currentpage this.pagecount) {
if (this.currentpage this.pagecount - 10) {
str.append("...");
str.append("a href='" + url + "currentpage="
+ (this.pagecount - 1) + "' hidefocus=\"true\""
+ (this.pagecount - 1) + "/a??");
str.append("a href='" + url + "currentpage="
+ this.pagecount + "' hidefocus=\"true\""
+ this.pagecount + "/a??");
}
str.append("a href='" + url + "currentpage=" + Nextpage
+ "' hidefocus=\"true\"下一頁(yè)/a");
str.append("??");
} else {
str.append("span class=\"disabled\"下一頁(yè)/span");
str.append("??");
}
if (this.pagecount 1 this.currentpage != this.pagecount) {
str.append("a href='" + url + "currentpage=" + pagecount
+ "' hidefocus=\"true\"尾頁(yè)/a");
str.append("??");
} else {
str.append("span class=\"disabled\"尾頁(yè)/span");
str.append("??");
}
str.append("/div");
}
return str.toString();
}
public String getParamUrl() {
String url = "";
url = this.request.getRequestURI().toString();
if (url.indexOf("?") == -1) {
url = url + "?";
}
String totalParams = "";
Enumeration params = this.request.getParameterNames();// 得到所有參數(shù)名
while (params.hasMoreElements()) {
String tempName = params.nextElement().toString();
String tempValue = this.request.getParameter(tempName);
if (tempValue != null !tempValue.equals("")
!tempName.equals("currentpage")) {
if (totalParams.equals("")) {
totalParams = totalParams + tempName + "=" + tempValue;
} else {
totalParams = totalParams + "" + tempName + "="
+ tempValue;
}
}
}
String totalUrl = url + totalParams;
return totalUrl;
}
}
head
%
const MaxPerPage=20
dim sql
dim rs
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
%
/head
body
%
conn = "DBQ=" + server.mappath("wj028.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
sql = "SELECT * FROM USER order by id desc"
set rs=server.createobject("adodb.recordset")
rs.open SQL,conn,1,1
rs.MoveFirst
rs.pagesize=MaxPerPage
howmanyfields=rs.Fields.Count-1
If trim(Request("Page"))"" then
CurrentPage= CLng(request("Page"))
If CurrentPage rs.PageCount then
CurrentPage = rs.PageCount
End If
Else
CurrentPage= 1
End If
if rs.eof then
response.write "p align='center'沒有記錄!/p"
else
totalPut=rs.recordcount
if CurrentPage1 then
if (currentPage-1)*MaxPerPagetotalPut then
rs.move(currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
end if
end if
dim n,k
if (totalPut mod MaxPerPage)=0 then
n= totalPut \ MaxPerPage
else
n= totalPut \ MaxPerPage + 1
end if%
% i=0
do while not rs.EOF and imaxperpage
%
%
rs.movenext
i=i+1
loop
%
第%=currentpage%頁(yè)
共%=n%頁(yè)
%
k=currentpage
if k1 then
response.write "[b"+"a href='list.asp?page=1'首頁(yè)/a/b]"
response.write "[b"+"a href='list.asp?page="+cstr(k-1)+"'上一頁(yè)/a/b]"
else
Response.Write "[首頁(yè)][上一頁(yè)]"
end if
if kn then
response.write "[b"+"a href='list.asp?page="+cstr(k+1)+"'下一頁(yè)/a/b] "
response.write "[b"+"a href='list.asp?page="+cstr(n)+"'尾頁(yè)/a/b] "
else
Response.Write "[下一頁(yè)][尾頁(yè)]"
end if
%
%
end if
set rs=nothing
set conn=nothing
%
/body
/**
*?分頁(yè)代碼
*?
*?@author?Star
*?@version?1.0?2008/07/08
*/
public?class?CutPage?implements?Serializable{
private?static?Log?log?=?LogFactory.getLog(CutPage.class);
private?int?curPageNo?=?0;?//?當(dāng)前頁(yè)數(shù),從0開始
private?int?size?=?0;?//?所有數(shù)據(jù)條數(shù)
private?String?url;?//?頁(yè)面跳轉(zhuǎn)的路徑
private?List?showList;?//?當(dāng)前頁(yè)面需要顯示的數(shù)據(jù)列表
private?int?pageSize?=?20;//?每頁(yè)顯示的數(shù)據(jù)條數(shù)
private?int?groupSize?=?1;//?多少頁(yè)為一組
private?String?pageNavigation;//?導(dǎo)航條
/**
?*?每次通過sql語(yǔ)句從數(shù)據(jù)庫(kù)里面分組取出需要顯示的數(shù)據(jù)
?*?
?*?@param?request
?*????????????javax.servlet.http.HttpServletRequest對(duì)象
?*?@param?sql
?*????????????String?查詢數(shù)據(jù)庫(kù)的sql語(yǔ)句
?*?@param?pageSize
?*????????????int?每頁(yè)顯示的條數(shù)
?*?@param?groupSize
?*????????????int?分成多少組
?*?@param?url
?*????????????String?頁(yè)面跳轉(zhuǎn)的路徑,若沒有特殊的參數(shù)傳遞,可以傳入null或"",
?*????????????如是在aciton里面調(diào)用,并且action是繼承自DispatherAction的話最好傳入完整的路徑
?*/
public?void?init(HttpServletRequest?request,?String?sql,?int?pageSize,
int?groupSize,?int?pageNo,?String?url)?{
//?上一頁(yè)、下一頁(yè)跳轉(zhuǎn)路徑
if?(url?!=?null)?{
this.url?=?url;
}?else?{
this.url?=?request.getRequestURL()?+?"";
}
if?(pageSize??0)
this.pageSize?=?pageSize;//?每頁(yè)多少條記錄
if?(groupSize??0)
this.groupSize?=?groupSize;
//?當(dāng)前第幾頁(yè)
if?(pageNo??0)?{
this.curPageNo?=?0;
}?else?{
this.curPageNo?=?pageNo;
}
int?curGroup?=?this.curPageNo?/?this.groupSize?+?1;
//?是否是新的一組數(shù)據(jù),如果是則到數(shù)據(jù)庫(kù)取數(shù)據(jù)
this.size?=?parseInt(request.getSession().getAttribute("page_all_size")
+?"",?0);
if?(this.curPageNo?%?this.groupSize?==?0
||?(request.getSession().getAttribute("cur_group")?!=?null??parseInt(
""?+?request.getSession().getAttribute("cur_group"),?1)?!=?curGroup)
||?this.size?==?0?||?request.getParameter("reload")?!=?null)?{
request.getSession().setAttribute("cur_group",?curGroup);
if?(pageNo??0
?request.getSession().getAttribute("page_sql")?!=?null)?{
sql?=?request.getSession().getAttribute("page_sql")?+?"";
}?else?{
request.getSession().setAttribute("page_sql",?sql);
}
this.size?=?getTotalCount(sql);
List?list?=?getPageData(sql,?(this.curPageNo?/?this.groupSize)
*?this.pageSize?*?this.groupSize,?this.pageSize
*?this.groupSize);
request.getSession().setAttribute("page_all_size",?this.size);
request.getSession().setAttribute("page_cur_list",?list);
this.setShowList(list);//?設(shè)置頁(yè)面上的顯示數(shù)據(jù)
}?else?{
this.setShowList((List)?request.getSession().getAttribute(
"page_cur_list"));//?設(shè)置頁(yè)面上的顯示數(shù)據(jù)
}
}
/**
?*?每次通過sql語(yǔ)句從數(shù)據(jù)庫(kù)里面分組取出需要顯示的數(shù)據(jù)
?*?
?*?@param?request
?*????????????javax.servlet.http.HttpServletRequest對(duì)象
?*?@param?sql
?*????????????String?查詢數(shù)據(jù)庫(kù)的sql語(yǔ)句
?*?@param?pageSize
?*????????????int?每頁(yè)顯示的條數(shù)
?*?@param?groupSize
?*????????????int?分成多少組
?*?@param?url
?*????????????String?頁(yè)面跳轉(zhuǎn)的路徑,若沒有特殊的參數(shù)傳遞,可以傳入null或"",
?*????????????如是在aciton里面調(diào)用,并且action是繼承自DispatherAction的話最好傳入完整的路徑
?*/
public?void?init(HttpServletRequest?request,?String?sql,?int?pageSize,
int?groupSize,?String?url)?{
//?當(dāng)前第幾頁(yè)
String?curPage?=?request.getParameter("pageNo");
init(request,?sql,?pageSize,?groupSize,?parseInt(curPage,?-1),?url);
}
/**
?*?每次通過sql語(yǔ)句從數(shù)據(jù)庫(kù)里面分組取出需要顯示的數(shù)據(jù)
?*?
?*?@param?request
?*????????????javax.servlet.http.HttpServletRequest對(duì)象
?*?@param?sql
?*????????????String?查詢數(shù)據(jù)庫(kù)的sql語(yǔ)句
?*?@param?pageSize
?*????????????int?每頁(yè)顯示的條數(shù)
?*?@param?groupSize
?*????????????int?分成多少組
?*?@param?url
?*????????????String?頁(yè)面跳轉(zhuǎn)的路徑,若沒有特殊的參數(shù)傳遞,可以傳入null或"",
?*????????????如是在aciton里面調(diào)用,并且action是繼承自DispatherAction的話最好傳入完整的路徑
?*/
public?void?init(HttpServletRequest?request,?String?sql,?int?pageSize,
int?groupSize,?int?pageNo)?{
init(request,?sql,?pageSize,?groupSize,?pageNo,?"");
}
太多了,貼不下,見附件
package dl.wsxx.base;
public class Pager {
private int totalRows; // 總行數(shù)
private int pageSize; // 每頁(yè)顯示的行數(shù)
private int currentPage; // 當(dāng)前頁(yè)號(hào)
private int totalPages; // 總頁(yè)數(shù)
private int startRow; // 當(dāng)前頁(yè)在數(shù)據(jù)庫(kù)中的起始行
private int pageStartRow; // 當(dāng)前頁(yè)開始行
private int pageEndRow; // 當(dāng)前頁(yè)結(jié)束行
private int hasNextPage; // 下一頁(yè)存在標(biāo)識(shí)[0:不存在,1:存在]
private int hasPreviousPage; // 前一頁(yè)存在標(biāo)識(shí)[0:不存在,1:存在]
public Pager() {
}
public Pager(int _totalRows,int _pageSize) {
pageSize = _pageSize;
totalRows = _totalRows;
totalPages = totalRows / pageSize;
int mod = totalRows % pageSize;
if (mod 0) {
totalPages++;
}
currentPage = 1;
startRow = 0;
}
public int getStartRow() {
return startRow;
}
public int getpageStartRow() {
return pageStartRow;
}
public int getpageEndRow() {
return pageEndRow;
}
public int getTotalPages() {
return totalPages;
}
public int getCurrentPage() {
return currentPage;
}
public int getPageSize() {
return pageSize;
}
public int getHasNextPage() {
return hasNextPage;
}
public int getHasPreviousPage() {
return hasPreviousPage;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
public void setStartRow(int startRow) {
this.startRow = startRow;
}
public void setPageStartRow(int pageStartRow) {
this.pageStartRow = pageStartRow;
}
public void setPageEndRow(int pageEndRow) {
this.pageEndRow = pageEndRow;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public void setHasNextPage(int hasNextPage) {
this.hasNextPage = hasNextPage;
}
public void setHasPreviousPage(int hasPreviousPage) {
this.hasPreviousPage = hasPreviousPage;
}
public int getTotalRows() {
return totalRows;
}
public void first() {
currentPage = 1;
startRow = 0;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void previous() {
if (currentPage == 1) {
return;
}
currentPage--;
startRow = (currentPage - 1) * pageSize;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void next() {
if (currentPage totalPages) {
currentPage++;
}
startRow = (currentPage - 1) * pageSize;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void last() {
currentPage = totalPages;
startRow = (currentPage - 1) * pageSize;
pageStartRow = startRow + 1;
this.hasFlagSet(currentPage, totalPages);
if (this.hasNextPage == 0) {
pageEndRow = totalRows;
} else {
pageEndRow = startRow + pageSize;
}
}
public void refresh(int _currentPage) {
currentPage = _currentPage;
if (currentPage totalPages) {
last();
}
this.hasFlagSet(currentPage, totalPages);
}
private void hasFlagSet(int currentPage, int totalPages) {
if (currentPage == totalPages) {
if (currentPage == 1) {
this.hasPreviousPage = 0;
this.hasNextPage = 0;
} else {
this.hasPreviousPage = 1;
this.hasNextPage = 0;
}
} else {
if (currentPage == 1) {
this.hasPreviousPage = 0;
this.hasNextPage = 1;
} else {
this.hasPreviousPage = 1;
this.hasNextPage = 1;
}
}
}
}
這是我的工程里的分頁(yè)核心代碼,希望對(duì)你有用,還有ssh分頁(yè)文檔,可以參照研究一下。
文章標(biāo)題:java中的分頁(yè)代碼 javaee分頁(yè)功能的實(shí)現(xiàn)和原理
文章路徑:http://jinyejixie.com/article44/ddojshe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、App開發(fā)、網(wǎng)站改版、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)