Mybatis paging plug-in, mybatis Paging
1.Description
If you are using Mybatis, we recommend that you try this paging plug-in, which must be the most convenient to use.
This plug-in currently supports six database tabs: Oracle, Mysql, MariaDB, SQLite, Hsqldb, and PostgreSQL.
2.
Usage
Step 1: configure the interceptor plug-in Mybatis configuration xml:
<Plugins> <! -- Com. github. pagehelper indicates the package name of the PageHelper class --> <plugin interceptor = "com. github. pagehelper. PageHelper"> <! -- Set the database type Oracle, Mysql, MariaDB, SQLite, Hsqldb, six PostgreSQL databases --> <property name = "dialect" value = "mysql"/> </plugin> </plugins>
Step 2: Use
1. Set paging information:
// Get the first page and 10 items. The total number of countPageHelper queries by default. startPage (1, 10); // The first select method that follows will be paged by List <Country> list = countryMapper. selectIf (1 );
2. Retrieve paging information
// After paging, the actual returned result list type is Page <E>. If you want to retrieve the paging information, you need to forcibly convert it to Page <E>, page <Country> listCountry = (Page <Country>) list; listCountry. getTotal ();
3. The second method for retrieving paging information
// Get the first page and 10 items. The total number of countPageHelper queries by default. startPage (1, 10); List <Country> list = countryMapper. selectAll (); // use PageInfo to wrap the result PageInfo page = new PageInfo (list ); // test all attributes of PageInfo // PageInfo contains a very comprehensive list of attributes assertEquals (1, page. getPageNum (); assertEquals (10, page. getPageSize (); assertEquals (1, page. getStartRow (); assertEquals (10, page. getEndRow (); assertEquals (183, page. getTotal (); assertEquals (19, page. getPages (); assertEquals (1, page. getFirstPage (); assertEquals (8, page. getLastPage (); assertEquals (true, page. isFirstPage (); assertEquals (false, page. isLastPage (); assertEquals (false, page. isHasPreviousPage (); assertEquals (true, page. isHasNextPage ());