Sprint Boot项目搭建STEP4:Sprint Boot Mybatis 分页整合

1.pom.xml添加com.github.pagehelper依赖后编译。

<dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>4.1.6</version>
        </dependency>

2.添加配置@Configuration文件,从Spring3.0,@Configuration用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,这些方法将会被AnnotationConfigApplicationContext或AnnotationConfigWebApplicationContext类进行扫描,并用于构建bean定义,初始化Spring容器。

Sprint Boot项目搭建STEP4:Sprint Boot Mybatis 分页整合

3.在SqlSessionFactory里添加该插件

Sprint Boot项目搭建STEP4:Sprint Boot Mybatis 分页整合

bean.setPlugins(new Interceptor[] { pageHelper });

4.使用