0
点赞
收藏
分享

微信扫一扫

MyBatisPlus插件扩展_PaginationInterceptor分页插件的使用


场景

实现

配置插件

来到项目下的applicationContext.xml中配置sqlSessionFactoryBean的地方。

<!--  配置SqlSessionFactoryBean
Mybatis提供的: org.mybatis.spring.SqlSessionFactoryBean
MP提供的:com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean
-->
<bean id="sqlSessionFactoryBean" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- 别名处理 -->
<property name="typeAliasesPackage" value="com.badao.beans"></property>
<!-- 注入全局MP策略配置 -->
<property name="globalConfig" ref="globalConfiguration"></property>
<!-- 插件注册 -->
<property name="plugins">
<list>
<!-- 注册分页插件 -->
<bean class="com.baomidou.mybatisplus.plugins.PaginationInterceptor"></bean>
</list>
</property>
</bean>

测试分页插件

编写单元测试

/***
* 分页插件
*/
@Test
public void testPagePlugin() {
Page<Employee> page = new Page<Employee>(1,2);
List<Employee> list=employeeMapper.selectPage(page, null);
for ( Employee employee : list) {
System.out.println("*******************"+employee.getName());
}
System.out.println("获取分页信息");
System.out.println("总条数"+page.getTotal());
System.out.println("当前页码"+page.getCurrent());
System.out.println("总页码"+page.getPages());
System.out.println("每页显示的条数"+page.getSize());
System.out.println("是否有上一页"+page.hasPrevious());
System.out.println("是否有下一页"+page.hasNext());

//将查询的结果直接封装到page对象中
page.setRecords(list);

}

Page对象

实现分页辅助类

MyBatisPlus插件扩展_PaginationInterceptor分页插件的使用_分页

 

继承了Pagination,所以也继承了方法。

运行单元测试

MyBatisPlus插件扩展_PaginationInterceptor分页插件的使用_spring_02


举报

相关推荐

0 条评论