maven需要添加的依赖
<!-- mybatis分页小插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.0</version>
</dependency>
mybatis中的配置
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!-- 分页合理化,如果页码<=0,就获得第一页;如果页数>max,就获得max-->
<property name="reasonable" value="true"/>
</plugin>
</plugins>
java代码
PageHelper.startPage(2, 3);
List<Person> list = session.selectList("person.list");
for (Person person : list) {
System.out.println(person);
}
PageHelper.clearPage();