Pagehelper分页插件-Mybatis
首先声明:Pagehelper这个mybatis插件网上有很多使用的教程,但使用时往往会有个别一直报错的,或者项目起不来的,主要还是版本问题,之前忽略了这个问题,找了各种方法,在maven里引入pagehelper的依赖时,总是项目起不来,网上有很多资料,就是没有找到对症下药的解决方法,琢磨了挺久,无意间在一篇文章上提到版本不兼容问题,于是找了各种版本做对应,最终实现此功能,主要是springboot、mybatis、和Pagehelper插件的版本要对应上,下面我贴出我的这三个的版本。
springboot
12 org.springframework.boot 3spring-boot-starter-parent 42.4.2 56
mybatis
12 org.mybatis.spring.boot 3mybatis-spring-boot-starter 41.3.2 5
Pagehelper
12 com.github.pagehelper 3pagehelper-spring-boot-starter 41.2.3 5
下面是具体使用方法,网上也有很多教程,我就贴出核心使用方法
serviceImpl
1 PageHelper.startPage(1,10); 2 Listlist = iInterfaceTable_oracle_dao.selectUser(); 3 PageInfo pageInfo = new PageInfo<>(list); 4 return pageInfo;
Controller
1 PageInfopageResult = iImportExcelService.selectUser(); 2 System.out.println(pageResult.getList()); 3 req.setAttribute("pageResult",pageResult);//前端获取时要在后面添加一个.list
前端
1 <div class="page"> 2 <div> 3 <p>${requestScope.pageResult.pageNum}/${requestScope.pageResult.pages}p> 4 <a class="prev" href="${pageContext.request.contextPath}/interfaceTable/getUser?pageNum=1">首页a> 5 <a class="prev" href="${pageContext.request.contextPath}/interfaceTable/getUser?pageNum=${requestScope.pageResult.prePage}">上一页a> 6 <a class="next" href="${pageContext.request.contextPath}/interfaceTable/getUser?pageNum=${requestScope.pageResult.nextPage}">下一页a> 7 <a class="next" href="${pageContext.request.contextPath}/interfaceTable/getUser?pageNum=${requestScope.pageResult.pages}">尾页a> 8 div> 9 div> 10 div>
展示