首先POM引入JAR包
方式一:
//PageHelper5 问题:若只引入artifactId:PageHelper,PageHelper.startPage()分页将会失效
<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>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
方式二:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
<version>1.2.4</version>
<version>1.2.7</version>
//以上三个版本哪个都行,问题:据说分页会有缓存,影响下有一次分页的分页参数组拼,导致分页数据不准确
</dependency>
下一步配置分页方言指定你用的数据库,具体支持哪些数据库,自行百度:
pagehelper. helper‐dialect=mysql
最后就可以编写mybatis代码,使用API进行分页了:
@Mapper
public interface mapper {
@Select("你的SQL语句")
Page<JAVABEAN> abc();
}
@Test
public void testMapper(){
PageHelper.startPage(1,5);
Page<JAVABEAN> retMethod= mapper.abc();
List<JAVABEAN> result = retMethod.getResult();
System.out.println(result);
}