PageHelper use supporting documentation
https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md
Use examples:
@RequestMapping (value = { " List " , "" }) Private String List (@RequestParam (value = " PN " , defaultValue = " . 1 " ) Integer PN, the Order Order, the HttpServletRequest Request, the HttpServletResponse Response, the Model Model) { / / startPage (pn, 3) the meaning is the current page number pn 3 wherein the article number of each page is displayed
PageHelper.startPage (pn, 3 );
// this is interacting with the database of a method List <the Order> = OrderList orderService.getOrdersByFactor (the Order);
// create objects using PageInfo his constructor contains two parameters, the first parameter is a query result list list, the second parameter is continuously displayed page number, such as page is now in the second page, the continuous display is: 1-2-3 page // if the page is now in the sixth, then the page is displayed: 5-6-7
PageInfo page = new new PageInfo (OrderList, 3 ); model.addAttribute ( " Page " , Page); // model.addAttribute ( "OrderList", OrderList ); return " modules / Goodman / orderList2 " ; }
After completion of the above query list of orders, followed by pageInfo package, this object is particularly useful, containing a lot of internal attributes, let us return into the foreground domain by Model Response object, use
Attributes as common object PageInfo
public class PageInfo <T> the implements the Serializable { Private static Final Long serialVersionUID = 1L ; // this page Private int pageNum; // page number Private int the pageSize; // number of this page Private int size; // Since startRow and endRow not common here that a specific usage // can "show startRow to endRow total size of data" in the page // first element of the current page line number in the database Private int startRow; // current page last element line number in the database Private intendRow; // total number of records Private Long Total; // Pages Private int Pages; // result set Private List <T> List; // Previous Private int prePage; // Next Private int nextPage; / / whether the first page of the Private boolean isFirstPage = false ; // whether the last page of the Private boolean isLastPage = false ; // Are there previous page Private boolean hasPreviousPage = false; // if a next Private Boolean = hasNextPage to false ; // Navigation Page number Private int navigatePages; // all navigation page number Private int [] navigatepageNums; // first page navigation bar Private int navigateFirstPage; // the last page on the navigation bar Private int navigateLastPage;
Three constructor PageInfo
Can be seen by the source code out in PageInfo this class contains three constructors, one with no parameters. Public PageInfo () { } 2 a parameter. Public PageInfo (List <T> List) { the this (List, . 8 ); } 3 . two parameters, where the first parameter is passed List <the Employee> the emps result set, will automatically packaged inside public PageInfo (List <T> List, int navigatePages) {....}
Of course, the need for the introduction of its dependence before using PageInfo plug-in project
1, into the pom.xml file
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.0.0</version> </dependency>
1, to mybatis configuration file to register the plug pageHelper
mybatis-config.xml
<! - plug-in configuration -> <-! @ Zjh20200407 registration page insert ->
<plugins>
<plugin Interceptor = "com.github.pagehelper.PageInterceptor"> </ plugin>
</ plugins>