/**
*
*/
package com.demo.PageUtil;
/**
* @author nsoft_hp_01
*
*/
public class PageSS {
/* 当前页号 */
private int currentPage = 1;
/* 总页数 */
private int totalPage;
/* 是否有上一页 */
private boolean hasPrePage = false;
/* 是否有下一页 */
private boolean hasNextPage = true;
/* 当前页记录开始索引 */
private int startIndex;
/* 记录总数 */
private int totalRows;
/* 每页记录数默认为10 */
private int pageSize = 12;
/* 页号记录 */
private int[] pages;
public PageSS() {
}
public PageSS(int totalRows,int pageSize) {
this.totalRows = totalRows;
setPageSize(pageSize);
if (totalRows % pageSize == 0) {
totalPage = totalRows / pageSize;
} else {
totalPage = totalRows / pageSize + 1;
}
pages = new int[totalPage];
for (int i = 0; i < totalPage; i++) {
pages[i] = i + 1;
}
if (totalPage == 1||totalPage == 0) {
hasPrePage = false;
hasNextPage = false;
}
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public boolean isHasPrePage() {
return hasPrePage;
}
public void setHasPrePage(boolean hasPrePage) {
this.hasPrePage = hasPrePage;
}
public boolean isHasNextPage() {
return hasNextPage;
}
public void setHasNextPage(boolean hasNextPage) {
this.hasNextPage = hasNextPage;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = (pageSize==0)?12:pageSize;
}
public int[] getPages() {
return pages;
}
public void setPages(int[] pages) {
this.pages = pages;
}
/**
* 返回到第一页
*/
public void first() {
if(totalPage!=0)currentPage = 1;
startIndex = 0;
// 如果总记录数不足一页,则该页行数为记录数
if(currentPage>1){
hasPrePage = true;
}else{
hasPrePage = false;
}
if(currentPage<totalPage){
hasNextPage = true;
}else{
hasNextPage = false;
}
if (totalRows < pageSize)
pageSize = totalRows;
}
/**
* 上一页
*/
public void previous() {
if (currentPage == 1) {
return;
}
// 设置第一页的hasPrePage;
--currentPage;
if(currentPage>1){
hasPrePage = true;
}else{
hasPrePage = false;
}
if(currentPage<totalPage){
hasNextPage = true;
}else{
hasNextPage = false;
}
startIndex = (currentPage - 1) * pageSize;
}
/**
* 下一页
*/
public void next() {
if (currentPage < totalPage) {
++currentPage;
}
// 设置新的页面的行数
if(currentPage>1){
hasPrePage = true;
}else{
hasPrePage = false;
}
if(currentPage<totalPage){
hasNextPage = true;
}else{
hasNextPage = false;
}
startIndex = (currentPage - 1) * pageSize;
if(currentPage == totalPage)pageSize = totalRows - startIndex;
}
/**
* 最后一页
*/
public void last() {
currentPage = totalPage;
if(currentPage>1){
hasPrePage = true;
}else{
hasPrePage = false;
}
if(currentPage<totalPage){
hasNextPage = true;
}else{
hasNextPage = false;
}
startIndex = (currentPage - 1) * pageSize;
pageSize = totalRows - startIndex;
}
/**
* 更新页面
*/
public void refresh(int currentPage) {
this.currentPage = currentPage;
if(currentPage>1){
hasPrePage = true;
}else{
hasPrePage = false;
}
if(currentPage<totalPage){
hasNextPage = true;
}else{
hasNextPage = false;
}
if ((totalRows - startIndex) < pageSize)
pageSize = totalRows - startIndex;
if (currentPage > totalPage) {
last();
}
}
}
评论4
最新资源