Struts paging one implementation

xiaoxiao2021-04-05  308

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 database access to the database accessed using the received paging parameter. (1) Paging Control Class Package Com.tower.util; Public Class PageController {Int TotalRowsamount; File: // Total Boilean RowsAmountSet; File: / / Whether it sets TotalrowSamount Int PageSize = 2; file: // Each page number INT currentPage = 1; file: // Current page number INT NEXTPAGE; int Previouspage; file: // Total Boolean Hasnext; File: File: // if a next boolean hasPrevious; file: // Is there a front String description; int pageStartRow; int pageEndRow; public PageController (int totalRows) {setTotalRowsAmount (totalRows);} public PageController () {} public void setTotalRowsAmount (int i) {if (! this.rowsAmountSet) {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 pageEndRow = currentPage * pageSize; pageStartRow = pageEndRow-pageSize 1;} else { pageEndRow = totalRowsAmount; pageStartRow = pageSize * (totalPages-1) 1;} if (nextPage> 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 getPageSize () {return pageSize;} public int getPreviousPage () {return previousPage;} public int getTotalPages () {return totalPages;

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

New Post(0)