- 导入依赖坐标
SSM依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.6</version>
</dependency>
SpringBoot依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
- MyBatis配置文件(整合在Spring)(Springboot不用这一步)
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="typeAliasesPackage" value="com.lagou.domain"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>helperDialect=mysql</value>
</property>
</bean>
</array>
</property>
</bean>
- 代码使用(Service层)
@Override
public PageInfo<PromotionAd> findAllPromotionAdByPage(PromotionAdVO promotionAdVO) {
PageHelper.startPage(promotionAdVO.getCurrentPage(),promotionAdVO.getPageSize());
List<PromotionAd> allPromotionAdByPage = promotionAdMapper.findAllPromotionAdByPage();
PageInfo<PromotionAd> pageInfo = new PageInfo<>(allPromotionAdByPage);
return pageInfo;
}