PaginationInnerInterceptor
分页插件
PaginationInnerInterceptor
在Spring配置文件
applicationContext.xml
中配置MyBatisPlus,注册分页插件
<bean id="sqlSessionFactoryBean" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- 别名处理 -->
<property name="typeAliasesPackage" value="testMP.bean"></property>
<!--注入MyBatisPlus全局策略配置-->
<property name="globalConfig" ref="globalConfig"></property>
<property name="plugins">
<array>
<ref bean="mybatisPlusInterceptor"></ref>
</array>
</property>
</bean>
<bean id="mybatisPlusInterceptor" class="com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor">
<property name="interceptors">
<list>
<!--注册分页插件-->
<ref bean="paginationInnerInterceptor"></ref>
</list>
</property>
</bean>
<bean id="paginationInnerInterceptor" class="com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor"></bean>
测试分页
@Test
public void testPaginationInnerInterceptor(){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
EmployeeMapper employeeMapper = context.getBean("employeeMapper",EmployeeMapper.class);
Page<Employee> employeePage = employeeMapper.selectPage(new Page<Employee>(2, 3), null);
List<Employee> records = employeePage.getRecords();
for (Employee employee : records){
System.out.println(employee);
}
}
打印日志: