irpas技术客

PageInfo介绍及使用_enterprising boy_pageinfo

未知 4619

1. MyBatis分页插件-PageHelper的配置

导入依赖

<!--引入PageHelper分页插件 → PageHelper--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.0.0</version> </dependency>

?mybatis-config.xml全局配置文件中配置拦截器插件

注意

?plugins在配置文件中的位置必须符合要求,否则会报错,顺序如下: ? ? properties?, settings?,? ? ? typeAliases?, typeHandlers?,? ? ? objectFactory?,objectWrapperFactory?,? ? ? plugins?,? ? ? environments?, databaseIdProvider?, mappers?

注意顺序

<plugins> <!-- com.github.pagehelper为PageHelper类所在包名 --> <plugin interceptor="com.github.pagehelper.PageInterceptor"> </plugin> </plugins> ?2. 分页的使用 Controller //查询全部的书籍,并且返回到一个书籍展示界面 @RequestMapping("/allBook") public String list(@RequestParam(value = "pn", required = true, defaultValue = "1") Integer pn, Model model){ //在查询之前调用,传入pn默认值是1,pageSize是5,意思是从第1页开始,每页显示5条记录。 PageHelper.startPage(pn, 5); //startPage后面紧跟查询就是一个分页查询。 List<Books> list = bookService.queryAllBook(); //使用PageInfo包装查询后的结果,只需要将PageInfo交给页面就行。 //封装了详细的分页信息,包括我们查询出来的数据userList,传入连续显示的页数5。 PageInfo<Books> page = new PageInfo<Books>(list, 5); model.addAttribute("pageInfo",page);//返回给前端展示 return "allBook"; } service //select all book List<Books> queryAllBook(); ?3. 页面使用

1). 头部引用 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 2). 页面使用

<div> <c:forEach items="${pageInfo.list}" var="books"> <tr> <th> ${epm.empId} </th> <th> ${epm.empName} </th> <th> ${epm.gender == "M"?"男":"女"}</th> <th> ${epm.email}</th> <th> ${epm.department.depName}</th> </tr> </c:forEach> </div> <%-- 分页文字信息 --%> <div class="col-md-6"> 当前第<span class="badge">${pageInfo.pageNum}</span>页,共有<span class="badge">${pageInfo.pages}</span>页,总计<span class="badge">${pageInfo.total}</span>条记录 </div> <nav aria-label="Page navigation"> <ul class="pagination"> <li class="prev"><a href="${pageContext.request.contextPath}/book/allBook?pn=${pageInfo.pageNum-1}">← Previous</a></li> <li class="${num == pageInfo.pageNum?'active':''}"> <c:forEach items="${pageInfo.navigatepageNums}" var="num"> <a href="${pageContext.request.contextPath}/book/allBook?pn=${num}">${num}</a> </c:forEach> </li> <li class="next"><a href="${pageContext.request.contextPath}/book/allBook?pn=${pageInfo.pageNum+1}">Next → </a></li> </ul> </nav>

全整合完报错了 ClassNotFoundException: com.github.pagehelper.PageInterceptor

转载请注明出处:Enterprising boy亲笔。

解决方法看下一篇博客 、

ClassNotFoundException: com.github.pagehelper.PageInterceptor_wangZY的博客-CSDN博客idea解决maven导入pageHelper插件,启动tomcat报ClassNotFoundException: com.github.pagehelper.PageInterceptor问题_C_bianchengxiaobai的博客-CSDN博客转载自idea解决maven导入pageHelper插件,启动tomcat报ClassNotFoundException: com.github.pagehelper.PageInterceptor问题_C_bianchengxiaobai的博客-CSDhttps://blog.csdn.net/NMdemon/article/details/121893293


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #pageinfo #1