mybatis use pagination plug PageHelper
The first step: introducing rely PageHelper in pom.xml
<!--分页插件--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.3</version> </dependency>
Step Two: Configure PageHelper pagination plug-in application.yml file
#分页插件 pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql
Entity class pagination plug-in: Step
Current page Private int pageNum; page number Private int pageSize; the current number of pages Private int size; // Since startRow and endRow not common here that a specific usage // can "show startRow to endRow total size in the page pieces of data " current page is the first element of a row number in the database Private int the startRow; this last element in the page line number in the database Private int endRow; the total number of records Private Long total; pages Private int pages; the result set Private List <T> List; first Private int firstPage; Previous Private int prePage; if the first page Private boolean isFirstPage = false ; whether the last page of the Private boolean isLastPage = false ; whether there are previous Private boolean hasPreviousPage = false ; if there is a next Private boolean hasNextPage = false ; navigation page number of Private int navigatePages; all navigation page number Private int [] navigatepageNums;
Step four: the use of the service layer
/** * 分类博客分页显示 * @param pageNum * @param pageSize * @param type * @return */ @Override public Object pageBlogType(int pageNum, int pageSize, String type) { PageHelper.startPage(pageNum, pageSize); List<Blogs> blogs = blogDao.searchTypeblog(type); PageInfo<Blogs> page = new PageInfo<>(blogs); return page; }
Code layer dao
// According to the classification queries blog List <Blogs> searchTypeblog (@Param ( "type") String type);