java分页计算当前页_java分页计算[通俗易懂]

java分页计算当前页_java分页计算[通俗易懂]java仿google的分页算法1.现将数据从数据库读取出来封装一个java类中,在java类中计算publicclassPage{//成员变量//当前页privateintnowpage;//总记录数privateintcountrecord;//总页数privateintcountpage;//当前页记录开始的位置privateintpageindex;//每页显示的…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

java仿google的分页算法

1.现将数据从数据库读取出来封装一个java类中,在java类中计算

public class Page {

//成员变量

//当前页

private int nowpage;

//总记录数

private int countrecord;

//总页数

private int countpage;

// 当前页记录开始的位置

private int pageindex;

// 每页显示的记录数

public static final int PAGESIZE = 5;

// 索引的sum值 代表的是 google页面中最大显示页数

private int sumindex = 6;

// 开始的索引值

private int startindex;

// 结束的索引值

private int endindex;

//当前页信息

private List allentities;

//构造器

public Page() {

}

public Page(int countrecord, int nowpage) {

// 计算当前页

this.nowpage = nowpage;

// 计算出当前页开始的位置

this.pageindex = (nowpage – 1) * PAGESIZE;

// 计算总页数

this.countrecord = countrecord;

if (this.countrecord % this.PAGESIZE == 0) {

this.countpage = this.countrecord / this.PAGESIZE;

} else {

this.countpage = this.countrecord / this.PAGESIZE + 1;

}

//计算开始和结束的索引值         //当当前页小于等于四时开始的索引值等于一,而结束的索引值分两种情况       if (this.nowpage <= 4) {           this.startindex = 1;           if (this.endindex > this.countpage) {               this.endindex = this.countpage;            }              this.endindex = this.nowpage + 2;       }          // 当当前页大于四时开始的索引值和结束的索引值均分三种情况         else if (this.nowpage > 4) {              if (this.endindex > this.countpage&& this.countpage < this.sumindex) {                   this.startindex = 1;               this.endindex = this.countpage;           }           else if (this.countpage > this.sumindex) {               this.startindex = this.countpage – 5;                   this.endindex = this.countpage;           }              else{                  this.startindex = this.nowpage – 3;               this.endindex = this.nowpage + 2;              }        }     }      //省略成员变量的get和set方法 }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/186371.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

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

关注全栈程序员社区公众号