1.pom文件中添加依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
2.在application.properties文件中加入pagehelper相关设置
#pagehelper分页插件配置
pagehelper.helperDialect=mysql
pagehelper.reasonable=false
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
pagehelper.reasonable=false 当该值为false时会根据传值去查找,当该值为true时总会查找到值
举个例子:你总共有10条数据,当你传值page=2 size=20的时候,当上边的值为true你总会查找到10条数据,当上边的值为false时就查不到数据了
3.使用
在启动类上加上
@SpringBootApplication
@MapperScan("com.chain.mapper")换上自己的mapper/dao的路径
实现类的方法上使用,在执行Mapper的方法前先设置PageHelper.startPage(pageNo, pageSize); 两行代码间尽量不要有其他的代码逻辑
PageHelper.startPage(pageNo, pageSize);
Page<Product> productList = productMapper.findByPage(classify);