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对象

实现分页辅助类
在这里插入图片描述
继承了Pagination,所以也继承了方法。
在这里插入图片描述

运行单元测试

在这里插入图片描述

本文转载自:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/89599657

posted @ 2019-09-30 16:47  抬头不见星空  阅读(673)  评论(0)    收藏  举报