【Video & Communication Platform】
http://study.163.com/course/introduction.htm?courseId=1004329008&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
http://study.163.com/course/introduction.htm?courseId=1004638001&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
https://gitee.com/happyangellxq520/spring-boot
à Spring Boot communication platform
http://412887952-qq-com.iteye.com/blog/2321532
[This blog has a supporting video, the video address: " Spring Boot MyBatis Upgrade - Annotation - Paging PageHelper does not take effect " , click the following to read the original text in the official account, and the video explains in more detail]
Origin of need:
Integrate PageHelper in MyBatis , and then add the following code where paging is required:
PageHelper.startPage(1,2);
But it doesn't take effect. All the data in the database is queried. What's going on?
( 1 ) Reason 1 : wrong version of mybatis-spring-boot-starter
This may be that you use the wrong version number, mainly the introduction of the version in the pom.xml file, the wrong version is introduced:
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.0.0</version> </dependency>
I have written it in detail in my blog, but there are still people who fall into the pit. The reason why this article appears is because someone has already fallen into the pit. Then the correct configuration is:
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.0</version> </dependency>
Please don't use version 1.0.0 , because interceptor plugins are not supported yet,
1.3.0 is the version when bloggers write posts, you can use the latest version
A newer version than this can theoretically run normally, unless the official website has made major adjustments.
(2)原因2:重新定义了SqlSessionFactory配置
第二种不好使的情况就是重新定义了SqlSessionFactory但是并没有配置对应的PageHelper插件,所以导致使用PageHelper.startPage(1,1);无效,那么如果要重新定义SqlSessionFactory的话,那么以下代码可以作为一个参考,其中红色部分是需要注意的地方:
@Bean public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Interceptor[] plugins = new Interceptor[]{pageHelper()}; sqlSessionFactoryBean.setPlugins(plugins); // 指定mybatisxml文件路径 sqlSessionFactoryBean.setMapperLocations(resolver .getResources("classpath:/mybatis/*.xml")); return sqlSessionFactoryBean.getObject(); }
总结:
总结下这个问题其一就是引入了错误的mybatis-spring-boot-starter版本,引用正确的版本即可; 其二就是重新定义SqlSessionFactory了,需要配置对应的PageHelper插件。
视频&交流平台:
http://study.163.com/course/introduction.htm?courseId=1004329008
http://412887952-qq-com.iteye.com/blog/2321532