Home>Article>Database> Detailed explanation of mybatis paging plug-in pageHelper instance

Detailed explanation of mybatis paging plug-in pageHelper instance

小云云
小云云 Original
2018-01-27 14:54:49 3142browse

The paging plug-in pageHelper is also a very important plug-in. This article mainly introduces the detailed explanation and simple examples of the mybatis paging plug-in pageHelper. Friends who need it can refer to it. I hope it can help everyone.

Mybatis paging plug-in pageHelper detailed explanation and simple example

Working framework spring springmvc mybatis3

First of all, you must use the paging plug-in first Introduce maven dependencies and add the following in pom.xml


  com.github.pagehelper pagehelper 3.7.5 

Secondly, you need to add configuration in the configuration file. There are two ways

1 , the content of the new mybatis-config.xml is as follows


             

Add a bean attribute in spring-mybatis.xml


 

Load the global configuration file


Configure mapper scanning and find all mapper.xml mapping files.


Note: If your mybatis-config.xml configuration file has the following alias configuration enabled:


   

Then your spring and mybatis integration file must add corresponding attributes, otherwise it will cause the mybatis configuration file to fail to load and report an exception, as follows:


        

Compared to the above We have one more step in the configuration here


When configuring, pay attention to the unified attributes of the mybatis configuration file and the spring-mybatis integration file.

2. The above operation configuration is completed, the second method below

Configure the following properties directly in spring-mybatis.xml


  
       
       
        
         
          
           
            dialect=mysql rowBoundsWithCount=true
           
          
         
        
       

After the configuration file is loaded, it can be used directly. The specific usage code is as follows:


PageHelper.startPage(Integer.parseInt(currentPage), Integer.parseInt(pageSize)); List publishTz = bbsTzDao.getPublishTz(userId); PageInfo info = new PageInfo(publishTz); map.put("status", 1); map.put("tzList", info.getList()); return map;

The parameters that need to be passed in to the front desk are the current page and page Display number. Of course, the page display number can also be specified in the background. Generally, it is best to add the default configuration when receiving parameters as follows:


@RequestParam(defaultValue="1",value="currentPage")String currentPage, @RequestParam(defaultValue="10",value="pageSize")String pageSize

This is if the received parameter is an empty string When it displays the page and number of items by default, you can define this yourself

The above is a simple application of pageHelper

Related recommendations:

SpringMvc+Mybatis+Pagehelper Detailed explanation of paging

bootstrap paginator paging plug-in usage method

jQuery Pagination paging plug-in detailed explanation

The above is the detailed content of Detailed explanation of mybatis paging plug-in pageHelper instance. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn