MyBatisPlus PaginationInterceptor分页 MyBatisPlus PaginationInterceptor分页插件的使用详解

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

MyBatisPlus PaginationInterceptor分页 MyBatisPlus PaginationInterceptor分页插件的使用详解

BADAO_LIUMANG_QIZHI   2021-03-24 我要评论
想了解MyBatisPlus PaginationInterceptor分页插件的使用详解的相关内容吗,BADAO_LIUMANG_QIZHI在本文为您仔细讲解MyBatisPlus PaginationInterceptor分页的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:MyBatisPlus,PaginationInterceptor分页,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,所以也继承了方法。

在这里插入图片描述

运行单元测试

在这里插入图片描述

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们