Templates for the Java paging model

Source: Internet
Author: User

Paged SQL


Select top number of records to display per page * from table name where primary key not in (select Top (number of records per page * (current page-1)) primary key from table name)

Select Top 5 * from UserInfo where ID not in (select Top (pno-1) with ID from userinfo)


Max pages
Total Records/pages per page if divisible, the maximum number of pages is the result,
If not divisible, the maximum number of pages is the result +1

If the total is 29, each page shows 5, the result is 29/5+1
If the total is 25, each page shows 5, the result is 25/5


Total number of data records
1. Use aggregate functions count queries Total
Select COUNT (primary key) from table name

2. Query all records, add to a collection, and use the. Size () method to get the total


Pagination Template
Property
1. Total Records count
2. Number of records displayed per page custom
3. Current page Dynamic acquisition
4. Maximum pages total record/number of records displayed per page

The pagination class written in the Help class

Package com.zuxia.util;

Import java.util.List;

public class Pagemodel<t> {

Define the current page number
private int pageno=1;
Define Display records per page
private int pagesize=5;
Number of bars in the total bar record
private int count;
Defines the collection of saved numbers
Private list<t> all;

/**
*
* Home
* @return
* */
public int GetIndex ()
{
return 1;
}
/**
* Previous Page
* @return
* */
public int Getprepage ()
{
int prvpage=pageno-1;
if (Prvpage <1)
{
prvpage=1;
}
return prvpage;
}
/**
* Last Page
* @return
* */
public int gettotal ()
{
int totablpage;
if (this.count%pagesize==0)
{
Totablpage=count/pagesize;
}
else{
Totablpage=count/pagesize;
}
return totablpage;
}

/**
* Next Page
* @return
* */

public int Getnextpage ()
{
int nextpage=pageno+1;
if (Nextpage>this.gettotal ())
{
Nextpage=this.gettotal ();
}
return Getnextpage ();
}



public int Getpageno () {
return pageno;
}
public void Setpageno (int pageno) {
This.pageno = PageNo;
}
public int getpagesize () {
return PageSize;
}
public void setpagesize (int pageSize) {
PageSize = PageSize;
}
public int GetCount () {
return count;
}
public void SetCount (int count) {
This.count = count;
}
Public List GetAll () {
return all;
}
public void SetAll (List all) {
This.all = ALL;
}
Public Pagemodel () {

}






}

Templates for the Java paging model

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.