分页插件 PageHelper pageHelper = new PageHelper; Properties properties = new Properties; propertiessetPropertyreasonable true; propertiessetPropertyrowBoundsWithCount true;
在PageHelper 5.X版本中,配置方式有所改变。可以按照以下方式进行配置:
- 使用新的PageInterceptor类替代原来的Interceptor类。导入新的依赖:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>5.x.x</version>
</dependency>
- 在application.properties或application.yaml文件中进行配置:
pagehelper:
helper-dialect: mysql
reasonable: true
params: count=countSql
- 在MyBatis的配置文件中添加PageInterceptor:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- ... other configurations -->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration">
<property name="properties" value="helperDialect=mysql;reasonable=true;params=count=countSql"/>
</bean>
</array>
</property>
</bean>
注意:根据你的数据库类型,将helper-dialect属性的值设置为对应的数据库方言,如mysql、oracle、postgresql等。
这样就可以将分页插件升级到PageHelper 5.X版本并进行配置了
原文地址: https://www.cveoy.top/t/topic/iVlf 著作权归作者所有。请勿转载和采集!