MyBatis___:关于MyBatis的分页PageHelper插件使用

1.

在maven中引入pagehelper相关依赖包:

<dependency>

    <groupId>com.github.pagehelper</groupId>

    <artifactId>pagehelper</artifactId>

    <version>5.1.2</version>

</dependency>



2.

在mybatis-config.xml注册分页插件

<plugins>

    <!-- com.github.pagehelper为PageHelper类所在包名 -->

    <plugin interceptor="com.github.pagehelper.PageInterceptor">

</plugin>

</plugins>

3.

在查询之前只需要调用传入的页面,以及每页的大小:

PageHelper.startPage(pn, 5);

4.

startPage后面紧跟的这个查询就是一个分页的查询

List<Employee> employees =   this.employeeService.getAll();

5.

使用怕个info包装查询后的结果:

PageInfo<Employee> pageInfo = new PageInfo<Employee>(employees);

6.

PageInfo封装了详细的分页信息,包括有我们查询出来的数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值