A common jsp PageBean

Source: Internet
Author: User

Package com. shaccp. web. util;
Import java. util. List;
Public class PageBean {
/**
*
*
* @ Author ppy
* Total totalRecords records
* List stores paging data.
* PageNo current page
* PageSize page size
* Query stores the user query string
* PageAction: Servlet or Action (struts) on the Operation page)
* Method (the method corresponding to the Action in struts)
*
*
*/
Private int totalRecords;
Private List list;
Private int pageNo;
Private int pageSize;
Private String query;
Private String pageAction;
Private String method;
Public void setPageAction (String pageAction ){
This. pageAction = pageAction;
}
Public void setMethod (String method ){
This. method = method;
}
Public List getList (){
Return list;
}
Public void setList (List list ){
This. list = list;
}
Public int getPageNo (){
Return pageNo;
}
Public void setPageNo (int pageNo ){
This. pageNo = pageNo;
}
Public int getPageSize (){
Return pageSize;
}
Public void setPageSize (int pageSize ){
This. pageSize = pageSize;
}
Public int getTotalRecords (){
Return totalRecords;
}
Public void setTotalRecords (int totalRecords ){
This. totalRecords = totalRecords;
}
Public void setQuery (String query ){
This. query = query;
}
/**
* Return method for getting the total number of pages
* TotalRecords % pageSize = 0? (TotalRecords/pageSize) :( totalRecords/pageSize + 1)
*
* @ Return
*/
Public int getTotalPages (){
Return (totalRecords + pageSize-1)/pageSize;
}
/**
* Get the homepage
*
* @ Return
*/
Public int getTopPage (){
Return 1;
}
/**
* Get the previous page
*
* @ Return
*/
Public int getPreviousPageNo (){
If (pageNo <= 1)
Return 1;
Else
Return (pageNo-1 );
}
/**
* Get the next page
*
* @ Return
*/
Public int getNextPageNo (){
If (pageNo> = getTotalPages ()){
Return getTotalPages () = 0? 1: getTotalPages ();
} Else {
Return pageNo + 1;
}
}
/**
* Get the last page
*
* @ Return
*/
Public int getBottomPageNo (){
Return getTotalRecords () = 0? 1: getTotalPages ();
}
// Method 1 of page navigation
Public String getPageToolBar1 (){
String str = "";
Str + = "<a href = '" + pageAction + "? Method = "+ method +" & userQuery ="
+ Query + "& pageNo =" + getPreviousPageNo () + "& pageSize ="
+ PageSize + "'> previous page </a> ";
Str + = "<a href = '" + pageAction + "? Method = "+ method +" & userQuery ="
+ Query + "& pageNo =" + getNextPageNo () + "& pageSize ="
+ PageSize + "'> next page </a> ";
Return str;
}
// Link method 2 of page navigation
Public String getPageToolBar2 (){
String str = "";
Int pageSplit = (pageNo/5) * 5;
For (int I = pageSplit-1; I <(pageSplit + 6); I ++ ){
If (I <= 0 ){
} Else if (pageNo = I ){
Str + = I + "";
} Else if (I> getTotalPages ()){
} Else {
Str + = "<a href = '" + pageAction + "? Method = "+ method
+ "& UserQuery =" + query + "& pageNo =" + I + "& pageSize ="
+ PageSize + "'>" + I + "</a>" + "";
}
}
Return str;
}
}

Related Article

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.