Java EE design for the page splitter

Source: Internet
Author: User

Because of the course design of database training, in the process of doing the project, it is necessary to make the project more normative structure and separation of responsibilities between the layers . Undoubtedly, the paging device is one of them.

1. This article only states how the paging device is implemented, and for other concepts of the pager, search for other network resources yourself.

2. for information on how to use Pagebean at each level, see the reference in this document 3

First, design and implementation

  

/** * Pager * @author Zen Johnny * @date November 11, 2017 PM 1:19:32 * @notice SQL Demo:select * FROM table LIMIT 5, 10; Retrieving record lines 6-15 */package com.cpms.entity.vo;import java.util.collections;import java.util.list;public class Pager< entity> {/** * holds data for the current page */private list<entity> entitys;/** * Number of rows per page (number of records), default = */private int pagesize;/** * Default per page record  Number 10 (for default constructor, no set method) */private static final int default_page_size = 10;/** * Total number of rows (number of records) */private int totalrows;/** * Total pages */private int totalpage;/** * Current page, default to first page */private int curpage = 1;/** * Previous page */private int prepage;/** * Next page */private I NT nextpage;/** * Database start pointer * Limit begin,offset m */private int begincursor;/** * Database Query record offset * in limit Begin,offset Offset */private Int offsetcursor;/** * constructor */public Pager () {This (0, default_page_size, 0, Collections.empty_li ST);} /** * constructor */public Pager (int curpage, int pageSize, int totalrows,list<entity> entitys) {this.entitys = Enti Tys;//↓ must set the total record and the number of records per page before you know "total pagesThis.totalrows = Totalrows;setpagesize (pageSize);//↓ Note: 1. Condition: Total Record Count totalrows and number of records per page PageSize 2. This calculation is very easy to produce precision loss settotalpage ();//↓ conditions: Total pages totalpagesetcurpage (curpage);// ↓ Condition: Current page number curpage and number of records per page pagesizesetbegincursor ();//↓ condition: Number of records per page pagesizesetoffsetcursor ();// ↓ Condition: Current page number curpagesetprepage ();//↓ Condition: Current Page page number curpage and Total pages totalpagesetnextpage ();} Public list<entity> Getentitys () {return entitys;} /** * Set the current page data object, private, external shielding, to prevent the destruction of the properties of the page consistency */private void Setentitys (list<entity> entitys) {this.entitys = Entitys;} public int getpagesize () {return pageSize;} /** * Set page size, private, external masking, prevent breaking the consistency of the various properties of the pager */private void setpagesize (int pageSize) {if (PageSize < 1) {pageSize = Default_pag E_size;} else {this.pagesize = pageSize;}} public static int getdefaultpagesize () {return default_page_size;} public int gettotalrows () {return totalrows;} /** * Set the total number of pages, private, external shielding, to prevent the destruction of the properties of the page consistency */private void settotalrows (int totalrows) {if (Totalrows < 1) this.totalrows = 0;e Lsethis.totalrows = totalrows;} public int gettotalpage () {RETUrn Totalpage;} /** * Set total number of pages, private, external shielding, to prevent the consistency of the various properties of the paging device */private void Settotalpage () {this.totalpage = (int) Math.ceil ((double) totalrows/ pageSize);} public int getcurpage () {return curpage;} public void setcurpage (int curpage) {if (Curpage < 1) This.curpage = 1;else if (curpage > Totalpage) this.curpage = Tota Lpage;elsethis.curpage = Curpage;} public int getprepage () {return prepage;} private void Setprepage () {this.prepage = Curpage-1;if (This.prepage < 1)//NOTE: this.prepage[current]this.prepage = 1;} public int getnextpage () {return nextPage;} /** * Set next page number, private, external shield, prevent breaking the consistency of the properties of the pager */private void Setnextpage () {this.nextpage = Curpage + 1;if (This.nextpage > Tota Lpage)//Note: this.nextpage[current]this.nextpage = totalpage;} public int getbegincursor () {return begincursor;} /** * Set a database query record when the start cursor, private, external shielding, to prevent the destruction of the paging device consistency */private void Setbegincursor () {this.begincursor = (curPage-1) * pageSize; }public int Getoffsetcursor () {return offsetcursor;} /** * Set the cursor offset, private, and external masking for database query records, and prevent the consistency of the properties of the paging device from being broken */private voiD setoffsetcursor () {this.offsetcursor = pageSize;} /** * If there is a previous page */public Boolean hasprepage () {if (this.prepage = = 1) {return false;} return true;} /** * If there is a next page */public Boolean hasnextpage () {if (this.nextpage = = This.totalpage) {return false;} return true;} @Overridepublic String toString () {return "Pager [entitys=" + Entitys + ", pagesize=" + PageSize + ", totalrows=" + totalr oWS + ", totalpage=" + Totalpage + ", curpage=" + Curpage + ", prepage=" + Prepage + ", nextpage=" + nextpage+ ", begincurs Or= "+ Begincursor +", offsetcursor= "+ Offsetcursor +"] ";}}

Ii. Reference Documents

1.[powerful Java paging device]http://blog.csdn.net/hcmdy/article/details/25251911

2.[java--Paged Query interface design and the implementation of the paging device]http://blog.csdn.net/u011659172/article/details/18231509

3.[java Web (11) Paging feature implementation]https://www.cnblogs.com/whgk/p/6474396.html

Java EE design for the page splitter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.