中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Java分頁實(shí)現(xiàn)代碼

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用
package com.page;

public class PageUtil {

 // 每頁顯示的條數(shù)
 private int pageSize;
 // 總共的條數(shù)
 private int recordCount;
 // 當(dāng)前頁面
 private int currentPage;

 public PageUtil(int pageSize, int recordCount, int currentPage) {
  this.pageSize = pageSize;
  this.recordCount = recordCount;
  setCurrentPage(currentPage);
 }

 // 構(gòu)造方法
 public PageUtil(int pageSize, int recordCount) {
  this(pageSize, recordCount, 1);
 }

 // 總頁數(shù)
 public int getPageCount() {
  // 總條數(shù)/每頁顯示的條數(shù)=總頁數(shù)
  int size = recordCount / pageSize;
  // 最后一頁的條數(shù)
  int mod = recordCount % pageSize;
  if (mod != 0)
   size++;
  return recordCount == 0 ? 1 : size;
 }

 // 包含,起始索引為0
 public int getFromIndex() {
  // System.out.println("from index:"+(currentPage-1) * pageSize);
  return (currentPage - 1) * pageSize;
 }

 // 不包含
 public int getToIndex() {
  // System.out.println("to index:"+Math.min(recordCount, currentPage *
  // pageSize));
  return Math.min(recordCount, currentPage * pageSize);
 }

 // 得到當(dāng)前頁
 public int getCurrentPage() {
  return currentPage;
 }

 // 設(shè)置當(dāng)前頁
 public void setCurrentPage(int currentPage) {
  int validPage = currentPage <= 0 ? 1 : currentPage;
  validPage = validPage > getPageCount() ? getPageCount() : validPage;
  this.currentPage = validPage;
 }

 // 得到每頁顯示的條數(shù)
 public int getPageSize() {
  return pageSize;
 }

 // 設(shè)置每頁顯示的條數(shù)
 public void setPageSize(int pageSize) {
  this.pageSize = pageSize;
 }

 // 得到總共的條數(shù)
 public int getRecordCount() {
  return recordCount;
 }

 // 設(shè)置總共的條數(shù)
 public void setRecordCount(int recordCount) {
  this.recordCount = recordCount;
 }
}


 

----------------------------------------------------------------------------------------------------------------------------------
下面的代碼是放在jsp里面的
----------------------------------------------------------------------------------------------------------------------------------
<%
PublishersDAO dao = PublishersDAO.getInstance();
List records = dao.getModels();
String pageStr = request.getParameter("page");
int currentPage = 1;
if (pageStr != null)
currentPage = Integer.parseInt(pageStr);
PageUtil pUtil = new PageUtil(10, records.size(), currentPage);
currentPage = pUtil.getCurrentPage();
%>


-----------下面這個(gè)是放在有變量的上面-------------------------------------------------------------------------------------------

<%
for (int i = pUtil.getFromIndex(); i < pUtil.getToIndex(); i++) {
PublisherModel model = (PublisherModel) records.get(i);
%>
中間是刪除修改之類的代碼
<%}%>


------------這個(gè)是結(jié)尾的----------------------------------------------------------------------------------------------------------

<tr><td width=100% bgcolor="#eeeeee" colspan=4 align="center">
記錄總數(shù)<%=pUtil.getRecordCount()%>條 當(dāng)前頁/總頁數(shù)<%=currentPage%>
/<%=pUtil.getPageCount()%>每頁顯示<%=pUtil.getPageSize()%>條
<a href="publishers.jsp?page=1">首頁</a>
<a href="publishers.jsp?page=<%=(currentPage - 1)%>">上頁</a>
<a href="publishers.jsp?page=<%=(currentPage + 1)%>">下頁</a>
<a href="publishers.jsp?page=<%=pUtil.getPageCount()%>">末頁</a>
</td></tr>

標(biāo)簽: 代碼

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:一個(gè)Go語言實(shí)現(xiàn)的web爬蟲

下一篇:一份精辟的俄羅斯方塊Java源碼(335行)