Maven+SSM利用PageHelper实现分页

本文介绍了如何在SSM(Spring、SpringMVC、MyBatis)项目中结合Maven和PageHelper实现高效的分页查询。步骤包括在pom.xml中导入PageHelper依赖,在applacationContext.xml中配置,controller层处理分页参数,service层调用PageHelper并获取PageInfo,最后在jsp页面上展示和处理分页,以及通过Ajax实现动态分页更新。
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值