分页插件
1. 引入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.3</version>
</dependency>
2. 配置拦截器
// 启动分页拦截器
configuration.addInterceptor(new PageInterceptor());
3. 使用
使用方式如下:
@Test
public void testPage() {
PageHelper.startPage(2, 2, false);
PageHelper.orderBy("name");
List<Country> countries = countryMapper.selectAll();
Assert.isInstanceOf(Page.class, countries);
}
分页功能需要借助 PageHelper 这个工具类,详细细节直接阅读 PageHelper 的源码即可,代码逻辑非常简单,想要正确使用并不困难。
Last updated