首页 技术 正文
技术 2022年11月19日
0 收藏 979 点赞 4,750 浏览 2845 个字

Pager.java

 package pers.kangxu.datautils.common; import java.io.Serializable;
import java.util.List; /**
*
* <b> 分页通用类 </b>
*
* @author kangxu
* @param <T>
*
*/
public class Pager<T> implements Serializable { /**
*
*/
private static final long serialVersionUID = 4542617637761955078L; /**
* currentPage 当前页
*/
private int currentPage = 1;
/**
* pageSize 每页大小
*/
private int pageSize = 10;
/**
* pageTotal 总页数
*/
private int pageTotal;
/**
* recordTotal 总条数
*/
private int recordTotal = 0;
/**
* previousPage 前一页
*/
private int previousPage;
/**
* nextPage 下一页
*/
private int nextPage;
/**
* firstPage 第一页
*/
private int firstPage = 1;
/**
* lastPage 最后一页
*/
private int lastPage;
/**
* content 每页的内容
*/
private List<T> content; // 以下set方式是需要赋值的
/**
* 设置当前页 <br>
*
* @author kangxu
*
* @param currentPage
*/
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
} /**
* 设置每页大小,也可以不用赋值,默认大小为10条 <br>
*
* @author kangxu
*
* @param pageSize
*/
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
} /**
* 设置总条数,默认为0 <br>
*
* @author kangxu
*
* @param recordTotal
*/
public void setRecordTotal(int recordTotal) {
this.recordTotal = recordTotal;
otherAttr();
} /**
* 设置分页内容 <br>
*
* @author kangxu
*
* @param content
*/
public void setContent(List<T> content) {
this.content = content;
} /**
* 设置其他参数
*
* @author kangxu
*
*/
public void otherAttr() {
// 总页数
this.pageTotal = this.recordTotal % this.pageSize > 0 ? this.recordTotal / this.pageSize + 1 : this.recordTotal / this.pageSize;
// 第一页
this.firstPage = 1;
// 最后一页
this.lastPage = this.pageTotal;
// 前一页
if (this.currentPage > 1) {
this.previousPage = this.currentPage - 1;
} else {
this.previousPage = this.firstPage;
}
// 下一页
if (this.currentPage < this.lastPage) {
this.nextPage = this.currentPage + 1;
} else {
this.nextPage = this.lastPage;
}
} // 放开私有属性
public int getCurrentPage() {
return currentPage;
} public int getPageSize() {
return pageSize;
} public int getPageTotal() {
return pageTotal;
} public int getRecordTotal() {
return recordTotal;
} public int getPreviousPage() {
return previousPage;
} public int getNextPage() {
return nextPage;
} public int getFirstPage() {
return firstPage;
} public int getLastPage() {
return lastPage;
} public List<T> getContent() {
return content;
} @Override
public String toString() {
return "Pager [currentPage=" + currentPage + ", pageSize=" + pageSize
+ ", pageTotal=" + pageTotal + ", recordTotal=" + recordTotal
+ ", previousPage=" + previousPage + ", nextPage=" + nextPage
+ ", firstPage=" + firstPage + ", lastPage=" + lastPage
+ ", content=" + content + "]";
} }

使用 PagerTester.java

 package pers.kangxu.datautils.utils; import java.util.ArrayList;
import java.util.List; import pers.kangxu.datautils.common.Pager; /**
* 分页数据测试
* <b>
*
* </b>
* @author kangxu
*
*/
public class PagerTester { public static void main(String[] args) { Pager<String> pager = new Pager<String>(); List<String> content = new ArrayList<String>();
content.add("str1");
content.add("str2");
content.add("str3");
content.add("str4");
content.add("str5");
content.add("str6");
content.add("str7");
content.add("str8");
content.add("str9");
content.add("str10"); pager.setCurrentPage(1);
pager.setPageSize(10);
pager.setRecordTotal(62);
pager.setContent(content); System.out.println(pager); } }
上一篇: JavaScript性能优化
下一篇: Ajax部分
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902