1.pom.xml中添加依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.0</version>
</dependency>
2.applicationContext.xml中配置
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties" value="reasonable=true"></property>
</bean>
</array>
</property>
<property name="typeAliasesPackage" value="com.bean"></property>
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
3.service层中使用
@Override
public List<ReaderPost> getReaderPost(int pageNum) {
PageHelper.startPage(pageNum,pageSize);
List<ReaderPost> readerPosts = newsDao.getReaderPost();
List<Type> typeList = newsDao.getAllTypes();
return readerPosts;
}