search
Homephp教程PHP开发Simple implementation of jsp paging

Data paging is essential in development. Because the amount of data is too large, it has to be processed. But for paging, there are many ways, such as using the limit of the sql statement, or using the jquery plug-in. But the underlying logic is all needed.
Post the code of the bean object and an auxiliary class here. The project I am working on is a personal blog, which can be regarded as a personal website.

(Only post some of the underlying logic code)

Page.java

package cn.edu.ldu.util;
 
public class Page {
 
  private int everyPage;     //每页显示的数量
  private int totalPage;     //总页数
  private int totalCount;     //总数量
  private int currentPage;    //当前页
  private int beginIndex;     //起始页
  private boolean hasPrepage;   //是否有上一页
  private boolean hasNextPage;  //是否有下一页
 
  public Page() {
  }
 
  public Page(int everyPage, int totalPage, int totalCount, int currentPage,int beginIndex, boolean hasPrepage, boolean hasNextPage)
  {
    this.everyPage = everyPage;
    this.totalPage = totalPage;
    this.totalCount = totalCount;
    this.currentPage = currentPage;
    this.beginIndex = beginIndex;
    this.hasPrepage = hasPrepage;
    this.hasNextPage = hasNextPage;
  }
 
  public int getEveryPage() {
    return everyPage;
  }
 
  public void setEveryPage(int everyPage) {
    this.everyPage = everyPage;
  }
 
  public int getTotalPage() {
    return totalPage;
  }
 
  public void setTotalPage(int totalPage) {
    this.totalPage = totalPage;
  }
 
  public int getTotalCount() {
    return totalCount;
  }
 
  public void setTotalCount(int totalCount) {
    this.totalCount = totalCount;
  }
 
  public int getCurrentPage() {
    return currentPage;
  }
 
  public void setCurrentPage(int currentPage) {
    this.currentPage = currentPage;
  }
 
  public int getBeginIndex() {
    return beginIndex;
  }
 
  public void setBeginIndex(int beginIndex) {
    this.beginIndex = beginIndex;
  }
 
  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;
  }
 
}

PageUtil.java

package cn.edu.ldu.util;
 
public class PageUtil {
  //创建分页信息对象
  public static Page createPage(int everyPage,int totalCount,int currentPage) {
    everyPage = getEveryPage(everyPage);
    currentPage = getCurrentPage(currentPage);
    int totalPage = getTotalPage(everyPage, totalCount);
    int beginIndex = getBeginIndex(everyPage, currentPage);
    boolean hasPrePage = getHasPrePage(currentPage);
    boolean hasNextPage = getHasNextPage(totalPage, currentPage);
    return new Page(everyPage, totalPage,totalCount, currentPage,
        beginIndex, hasPrePage, hasNextPage);
  }
 
  //获得每页显示记录数
  public static int getEveryPage(int everyPage) {
    return everyPage == 0 ? 10 : everyPage;
  }
 
  //获得当前页
  public static int getCurrentPage(int currentPage) {
    return currentPage == 0 ? 10 : currentPage;
  }
 
  //获得总页数
  public static int getTotalPage(int everyPage,int totalCount) {
    int totalPage=0;
    //要判断每页是否满页,否则页数+1
    if(totalCount!=0 && totalCount%everyPage==0) {
      totalPage=totalCount/everyPage;
    }
    else {
      totalPage=totalCount/everyPage+1;
    }
    return totalPage;
  }
 
  //获得起始位置
  public static int getBeginIndex(int everyPage,int currentPage) {
    return everyPage*(currentPage-1);
  }
 
  //判断是否有上一页
  public static boolean getHasPrePage(int currentPage) {
    return currentPage== 1 ? false : true;
 
  }
 
  //判断是否有下一页
  public static boolean getHasNextPage(int totalPage, int currentPage) {
    return (currentPage == totalPage) || (totalPage == 0) ? false : true;
  }
 
}

I only need to call it every time.

//传入每页显示的页数,总记录数,当前页
Page page=PageUtil.createPage(5, diaryDao.findAllCount(), currentPage);

Simple implementation of jsp paging

The above is the entire content of this article. I hope it will be helpful to everyone's learning, and I also hope that everyone will join the PHP Chinese website.


For more articles related to the simple implementation of jsp paging, please pay attention to the PHP Chinese website!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor