转载地址:https://blog.csdn.net/weixin_42145761/article/details/103951029
SpringBoot和PageHelper的集成与SSM框架的集成有一些不一样,在这里主要说一下jar包和配置。
SSM框架与PageHelper的集成:
1、添加jar包
<!--分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
2、配置mybatis.xml文件
<!--配置分页插件-->
<plugins>
<!-- com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!-- 合理化物理分页 -->
<property name="reasonable" value="true"/>
</plugin>
</plugins>
3、在applicationContext.xml中配置工厂
<!--SqlSessionFactory-->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--连接池-->
<property name="dataSource" ref="dataSource"/>
<!--个性配置文件,在这里主要把mybatis.xml引入-->
<property name="configLocation" value="classpath:mybatis.xml"/>
<!--别名-->
<property name="typeAliasesPackage" value="com.jzh.crm2.domain"/>
<!--管理的mapper文件-->
<property name="mapperLocations" value="classpath:com/jzh/crm2/mapper/*Mapper.xml"/>
</bean>
Spring Boot与PageHelper的集成
1、添加jar包(这里是最主要的,比SSM多添加了两个依赖jar包)
<!--分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
2、在application.peoperties中添加一些配置
#pagehelper分页插件配置
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql