Java paging code implementation 2

Source: Internet
Author: User

Public class pagesplit {
Int page = 1; // request to display the page
Int COUNT = 1; // The total number of records.
Int currentpage = 1; // The currentpage is displayed.
Int pagecount = 1; // total number of pages
Int rows = 1; // number of lines displayed per page
List list = NULL;

/**
* Constructor 1
*
* @ Param list: list object for paging
*/
Public pagesplit (list ){
Super ();
This. List = List;
}

/**
* Constructor 2
*
* @ Param rows
* Number of lines displayed per page
* @ Param list
* List objects to be paged
*/
Public pagesplit (INT rows, list ){
Super ();
This. rows = rows;
This. List = List;
}

/**
* Return all content on the page. The result is still in list type.
*
* @ Param page: returns the content of the page.
* @ Return
*/
Public list currentlist (INT page ){
This. Page = page;
Currentpage = page;
Count = List. Size ();
Pagecount = (count + rows-1)/rows; // displays the number of rows based on the total number of records.

/* If the request page is smaller than 1, make the current page count equal to 1 */
If (currentpage <1 ){
Currentpage = 1;
}
/* If the number of request pages is greater than the total number of pages, set the current number of pages to the total number of pages */
If (currentpage> pagecount ){
Currentpage = pagecount;
}

List newlist;
/* Not full page */
If (currentpage-1) * Rows) + rows)> count ){
Return newlist = List. sublist (currentpage-1) * Rows, count );
}
/* The page is full */
Else {
Return newlist = List. sublist (currentpage-1) * Rows,
(Currentpage-1) * Rows) + rows );
}
}

Public int getpage (){
Return page;
}

Public void setpage (INT page ){
This. Page = page;
}

Public int getcount (){
Return count;
}

Public void setcount (INT count ){
This. Count = count;
}

Public int getcurrentpage (){
Return currentpage;
}

Public void setcurrentpage (INT currentpage ){
This. currentpage = currentpage;
}

Public int getpagecount (){
Return pagecount;
}

Public void setpagecount (INT pagecount ){
This. pagecount = pagecount;
}

Public int getrows (){
Return rows;
}

Public void setrows (INT rows ){
This. rows = rows;
}
}

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.