首页 / JAVA / JAVA 分页原生代码
JAVA 分页原生代码
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JAVA 分页原生代码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2300字,纯文字阅读大概需要4分钟。
内容图文
![JAVA 分页原生代码](/upload/InfoBanner/zyjiaocheng/837/8bf9ce6498344747818388ad7f9ebb13.jpg)
Pager
package com.wtz.util;
import java.util.List;
public class Pager<T> {
private Integer pageSize;
private Integer totalRecord;
private Integer totalPage;
private Integer currentPage;
private List<T> list;
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public Integer getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(Integer totalRecord) {
this.totalRecord = totalRecord;
}
public Integer getTotalPage() {
return totalPage;
}
public void setTotalPage(Integer totalPage) {
this.totalPage = totalPage;
}
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public List<T> getList() {
return list;
}
public void setList(List<T> list) {
this.list = list;
}
public Pager(Integer pageNo,Integer pageSize,List<T> sourceList){
if(sourceList==null){
return;
}
//总记录数
this.totalRecord = sourceList.size();
//每页显示多小条数据
this.pageSize = pageSize;
//总页数
this.totalPage = this.totalRecord % this.pageSize == 0?this.totalRecord/this.pageSize:this.totalRecord/this.pageSize+1;
//当前第几页
if(this.totalPage < pageNo){
this.currentPage = this.totalPage;
}else{
this.currentPage = pageNo;
}
//起始索引
Integer fromIndex = this.pageSize * (this.currentPage - 1);
//结束索引
Integer endIndex = null;
if(this.pageSize * this.currentPage >this.totalRecord){
endIndex = this.totalRecord;
}else{
endIndex = this.pageSize * this.currentPage;
}
this.list = sourceList.subList(fromIndex, endIndex);
}
@Override
public String toString() {
return "Pager [pageSize=" + pageSize + ", totalRecord=" + totalRecord + ", totalPage=" + totalPage
+ ", currentPage=" + currentPage + ", list=" + list + "]";
}
}
Test
public class Test {
public static void main(String[] args) {
List<BgApply> list = new ArrayList<>();
BgApply bg1 = new BgApply();
bg1.setBatch("1");
list.add(bg1);
BgApply bg2 = new BgApply();
bg1.setBatch("2");
list.add(bg2);
BgApply bg3 = new BgApply();
bg1.setBatch("3");
list.add(bg3);
BgApply bg4 = new BgApply();
bg1.setBatch("4");
list.add(bg4);
BgApply bg5 = new BgApply();
bg1.setBatch("5");
list.add(bg5);
BgApply bg6 = new BgApply();
bg1.setBatch("6");
list.add(bg6);
BgApply bg7 = new BgApply();
bg1.setBatch("7");
list.add(bg7);
Pager<BgApply> pager = new Pager<>(1, 3, list);
System.out.println(pager);
}
}
内容总结
以上是互联网集市为您收集整理的JAVA 分页原生代码全部内容,希望文章能够帮你解决JAVA 分页原生代码所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。