在实际项目开发中,我们肯定需要对 LIST 接口进行分页和查找分页
物理分页实现方式:
第一种:在AOP 中利用 com.github.pagehelper 中的类 PageInterceptor(实现了Mybatis的Interceptor接口,调用拦截StatementHandler(Sql语法的构建处理)方法,按照物理库的不同重构SQL实现分页)
第二种:在配置类中实例化 MybatisPlusInterceptor 同时用注解 @Bean 注册到 Spring 容器中即纳入 spring 容器的管理
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
@Configuration
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor paginationInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
恒星数据库项目中的: MybatisPlus 插件的使用的场景是
对前端页面的某个资源列表,需要在多列上模糊搜索某个字符串同时以某个列排序
1.plugin 拦截 SQL, 修改 SQL, 再去执行后的 SQL
2.配置文件中 mybatis-config.xml 指定plugin的位置,才能让 plugin 生效