1.导入PageHelper需要的坐标
使用PageHelper需要导入两个坐标:pagehelper和jsqlparser
2.在MyBatis核心配置文件中配置PageHelper插件
我导入的pagehelper是5.3.0版本,所以在MyBatis的配置文件中进行如下配置:
<!--配置分页助手插件-->
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
3.测试分页数据获取
只需要在findAll()之前加上一条语句就好了``PageHelper.startPage(1, 3);```,干净又卫生
下面的测试数据的全部代码:
public class MapperTest {
@Test
public void testQuery() throws IOException {
InputStream resourceAsStream = Resources.getResourceAsStream("SqlMapConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
// openSession()的autoCom