SpringBoot-- use Mybatis pagination plug-in

1, and introduced into the plug-in package jpa paging packet

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>

2, increase paging configuration

# Primary key from write-back method by default value MYSQL, details see documents 
Mapper: 
  the Identity: MYSQL 
# Set the insert and update, to determine whether the string type = ''! 
  Not -empty: to true 
# simple enumeration by type of treatment 
  enum -as-the Simple-of the type: to true 
######### pagination plug ########## 
pagehelper: 
  Helper - dialect: MySQL 
  params: 
    COUNT: countSql 
  Reasonable: false 
  Support -methods-arguments The : to true

Configuration instructions:

  mapper.enum-as-simple-type: enum type in a simple process, if you need to add the enumeration field configuration will do the mapping
  mapper.not-empty: after setting, is determined to insert and update the string type = '' "!

  pagehelper.reasonable:. rationalization paging parameter defaults to false when the parameter is set to true, pageNum <= 0, the first page queries, pageNum> pages (more than the total number), and finally queries . a default false, according to directly query parameters.
  support-methods-arguments: support tab to pass parameters Mapper interface parameter, the default value false, plug tab will automatically configure the parameter values from the query according to the above method of params field values, automatically paged when looking to the appropriate value.

 

3, using plug-in paging query

    public PageInfo<User> selectByUsername(String username,int limit, int page){
        PageHelper.startPage(page, limit).setOrderBy("id desc");
        PageInfo<User> userPageInfo = new PageInfo<>(this.userMapper.selectByuserName(username));
        return userPageInfo;
    }

4, the test

Here is not to write and call the middle class Controller Service, a direct call to see results

 

 

 

Guess you like

Origin www.cnblogs.com/liconglong/p/11693782.html