pom.xml
<!--PageHelper 分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.11</version>
</dependency>
</dependencies>
mybatis.xml
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!--分页参数合理化 -->
<property name="reasonable" value="true"/>
</plugin>
</plugins>
测试代码
public void testSelectAll(){
SqlSession sqlSession = MyBatisUntils.getOneSession();
StudentDao studentDao = sqlSession.getMapper(StudentDao.class);
//在list获取数据前使用PageHelper.startPage方法设置获取到的数据
//获取第 1 页,3 条内容
PageHelper.startPage(1,3);
List<Student> list = studentDao.SelectAll();
for(Student student:list){
System.out.println(student);
}
}