获取内容资料
Java编程

java分页教程

使用JAVA8的API可以实现分页,在数据量相对稳定的情况下,可以查出所有数据,配合缓存使用

import java.util.ArrayList;import java.util.List;import java.util.Optional;/*** @version 1.0* @author levelmini* @param */public class Page {private int current_page;private int size;private int total_page;private int total_sum;private transient List instanceList;//Gson不序列化transient字段private List currentPageData;private transient Optional> op;public Page(List instanceList,int size) {this.size = size;setInstanceList(instanceList);}public int getCurrent_page {return current_page;}public void setCurrent_page(int current_page) {this.current_page = current_page<1?1:current_page>this.total_page?this.total_page:current_page;setCurrentPageData(currentPageData);}public int getSize {return size;}public void setSize(int size) {this.size = size;}public int getTotal_page {return total_page;}public int getTotal_sum {return total_sum;}public List getInstanceList {return instanceList;}public void setInstanceList(List instanceList) {this.op= Optional.ofNullable(instanceList);this.instanceList = op.orElse(new ArrayList);this.total_sum = this.instanceList.size;this.total_page =(int) Math.ceil(1.0*this.total_sum/this.size);}public void setCurrentPageData(List currentPageData) {this.currentPageData = currentPageData;}public List getCurrentPageData{return this.currentPageData;}private List currentPageData{if(this.size==0

this.total_page == 1){return this.instanceList;}List currentPageData = new ArrayList;instanceList.stream.skip((this.current_page-1)*this.size).limit(this.size).forEach(e->currentPageData.add(e));return currentPageData;}}用法:

java将word转换为html(代码)盘点Java中的各种锁notepad++如何把文件保存为java文件java类加载机制详细介绍JAVA8的分页工具web负载均衡webpack简介安装 webpack网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论立即提交专题推荐独孤九贱-php全栈开发教程全栈 100W+

主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门

玉女心经-web前端开发教程入门 50W+

主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门

天龙八部-实战开发教程实战 80W+

主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习

最近文章win10安装.Net Framework 3.5 sp14460win10怎么连接外国网络5252win10更新1909要多久6256发布技术文章最新文章热门排行

myeclipse如何导出项目Java 的 AutoCloseable 接口rpc框架有哪些java正则表达式用法是什么java敏感异常有哪些java中object方法有哪些jstack命令详解java接口的修饰符可以为什么

苏ICP备2020058653号-1

Similar Posts

发表评论

邮箱地址不会被公开。 必填项已用*标注