分頁實體類:PageBean


 

 

package com.eaju.soms.entity.custom;

import java.util.List;

@SuppressWarnings("rawtypes")
public class PageBean {

// 傳遞的參數或是配置的參數
private int currentPage; // 當前頁
private int pageSize; // 每頁顯示多少條記錄

// 查詢數據庫
private List recordList; // 本頁的數據列表
private int recordCount; // 總記錄數

// 計算
private int pageCount; // 總頁數
private int beginPageIndex; // 頁碼列表的開始索引(包含)
private int endPageIndex; // 頁碼列表的結束索引(包含)

public PageBean() {
super();
}

/**
* 只接受4個必要的屬性,會自動的計算出其他3個屬性的值
*
* @param currentPage
* @param pageSize
* @param recordList
* @param recordCount
*/
public PageBean(int currentPage, int pageSize, List recordList, int recordCount) {
this.currentPage = currentPage;
this.pageSize = pageSize;
this.recordList = recordList;
this.recordCount = recordCount;

// 計算 pageCount
pageCount = (recordCount + pageSize - 1) / pageSize;

// 計算 beginPageIndex 與 endPageIndex
// >> 總頁碼小於等於10頁時,全部顯示
if (pageCount <= 10) {
beginPageIndex = 1;
endPageIndex = pageCount;
}
// >> 總頁碼大於10頁時,就只顯示當前頁附近的共10個頁碼
else {
// 默認顯示 前4頁 + 當前頁 + 后5頁
beginPageIndex = currentPage - 4; // 7 - 4 = 3;
endPageIndex = currentPage + 5; // 7 + 5 = 12; --> 3 ~ 12

// 如果前面不足4個頁碼時,則顯示前10頁
if (beginPageIndex < 1) {
beginPageIndex = 1;
endPageIndex = 10;
}
// 如果后面不足5個頁碼時,則顯示后10頁
else if (endPageIndex > pageCount) {
endPageIndex = pageCount;
beginPageIndex = pageCount - 9;
}
}
}

public List getRecordList() {
return recordList;
}

public void setRecordList(List recordList) {
this.recordList = recordList;
}

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 getRecordCount() {
return recordCount;
}

public void setRecordCount(int recordCount) {
this.recordCount = recordCount;
}

public int getBeginPageIndex() {
return beginPageIndex;
}

public void setBeginPageIndex(int beginPageIndex) {
this.beginPageIndex = beginPageIndex;
}

public int getEndPageIndex() {
return endPageIndex;
}

public void setEndPageIndex(int endPageIndex) {
this.endPageIndex = endPageIndex;
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM