spring boot pagination plug-in integrated mybatis

Pagination plug mybatis can save, this chapter is spring boot record of integrating mybatis pagination plug-ins.

1, rely on the introduction of

<!-- 分页插件pagehelper -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <Version> 1.2 .3</version>
        </ dependency> 
        <-! pagination plug pagehelper ->

2, the configuration file application.yml

Note  pagehelper is a root and spring at the same level

spring:
  mvc:
    view:
      prefix: /
      suffix: .jsp
  datasource:
    url: jdbc:mysql://localhost:3306/myrec?characterEncoding=utf8&useSSL=true
    username: root
    password: m123456
    driver-class-name: com.mysql.jdbc.Driver
       
#配置分页插件pagehelper
pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql

3, the use of business layer

/**
     * 按分页查询
     */
    @Override
    public PageResult findPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<Loginuser> page=   (Page<Loginuser>) loginuserMapper.selectByExample(null);
        return new PageResult(page.getTotal(), page.getResult());
    }

Do not guide the wrong bag

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

 

Guess you like

Origin www.cnblogs.com/zeussbook/p/11244174.html