Struts paging is an implementation! (One)

zhaozj2021-02-16  57

Seeing that everyone's enthusiasm for Struts is very enthusiastic, and this information is very small. Looking at everyone is very tired, so it is kind, seeing a good paging method, and put it out to share together! (Originally in javaworld), there is an imperfect place, I hope everyone will correct! ! !

Use a page control class, which record page information, such as page, next page, current page, etc. In the action of the query, this control class and query conditions are passed to the database access bean and then save the two parameters in the user session. In paging control Action, the BEAN access to the database is called using the received paging parameters.

(1) Pieces Control class

package com.tower.util; public class PageController {int totalRowsAmount; file: // total number of lines boolean rowsAmountSet; file: // is set too totalRowsAmount int pageSize = 2; file: // Number of lines per page int currentPage = 1; file : // Current page number INT NEXTPAGE; INT PREVIOUSPAGE; file: // Total page Boolean Hasnext; file: // Is there a next page Boolean Hasprevious; file: // Is there a previous page String Description; int PageStrow ; int pageEndRow; public PageController (int totalRows) {setTotalRowsAmount (totalRows);} (! this.rowsAmountSet) public PageController () {} public void setTotalRowsAmount (int i) {if {totalRowsAmount = i; totalPages = totalRowsAmount / pageSize 1 ; setCurrentPage (1); this.rowsAmountSet = true;}} public void setCurrentPage (int i) {currentPage = i; nextPage = currentPage 1; previousPage = currentPage-1; file: // calculate this page begins and ending lines IF (currentpage * pagesize totalPages) {hasNext = false;} else {hasNext = true;} if (previousPage == 0) {hasPrevious = false;} else {hasPrevious = true;}; System.out.println (this.description ());} public int getCurrentPage () {return currentPage;} public boolean isHasNext () {return hasNext;} public boolean isHasPrevious () {return hasPrevious;} public INT getNextPage () {Return nextPage;} public int getpage;} public int gettotalpage;};

} Public int getTotalRowsAmount () {return totalRowsAmount;} public void setHasNext (boolean b) {hasNext = b;} public void setHasPrevious (boolean b) {hasPrevious = b;} public void setNextPage (int i) {nextPage = i;} public void setPageSize (int i) {pageSize = i;} public void setPreviousPage (int i) {previousPage = i;} public void setTotalPages (int i) {totalPages = i;} public int getPageEndRow () {return pageEndRow;} public int getPageStartRow () {return pageStartRow;} public String getDescription () {String description = "Total:" this.getTotalRowsAmount () "items" this.getTotalPages () "pages"; // this.currentPage "Previous " this.hasprevious //" Next: " this.hasnext //" Start Row: " this.pagestRow //" End Row: " this.pageendrow; return description;} public string description;} public string description; Description = "Total:" this.gettotalrowsamount () "Items" this.gettotalpages () "Pages, Current Page:" this.currentPage "Previous" this.hasprevio us "Next:" this.hasNext "start row:" this.pageStartRow "end row:" this.pageEndRow; return description;} public static void main (String args []) {PageController pc = new PageController ( 3); system.out.println (pc.getdescription ()); // pc.setcurrentpage (2); // system.out.println (pc.description ()); // pc.setcurrentpage (3); / / System.out.println (pc.description ());

转载请注明原文地址:https://www.9cbs.com/read-22349.html

New Post(0)