1.导入jar包
在pom配置文件中,引入jar包,如果是分模块的可以在总的pom文件下引入。
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
2.在applacationContext.xml中配置PageHelper
加在<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">... ...</bean>
中
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<props>
<prop key="helperDialect">mysql</prop>
<prop key="resonable">true</prop> //最后页的下一页或者首页的上一页时,自动处理错误
</props>
</property>
</bean>
</array>
</property>
3.在controller层请求时候传递2个参数:当前页,每页的条数
@RequestMapping("/findAll.do")
public String getAllDoctor(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int size) {
List<Doctor> all = docService.getAllDoctor(page, size); //得到所有信息
//...
}
@RequestParam(defaultValue = "1")
、@RequestParam(defaultValue = "5")
设置没有参数的时候默认值
4.在service层,调用dao的查询所有记录前添加PageHelper
@Override
public List<Doctor> getAllDoctor(int page, in