- 添加相关的依赖
- 在applicationContext中添加依赖
//服务层 serviceImpl@Overridepublic List<Orders> findAll(Integer page,Integer size) throws Exception{ PageHelper.startPage(page,size); return ordersDao.findAll();}//controller层@Autowiredprivate IOrdersService iOrdersService;@RequestMapping("/findAll.do")public ModelAndView findAll(@RequestParam(name = "page") Integer page, @RequestParam(name = "size")Integer size) throws Exception{ List<Orders> ordersList = iOrdersService.findAll(page,size); PageInfo pageInfo = new PageInfo(ordersList); ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("pageInfo",pageInfo); modelAndView.setViewName("orders-list"); return modelAndView;}
<c:forEach items="${pageInfo.list}" var="orders"> <tr> <td><input name="ids" type="checkbox"></td> <td>${orders.id }</td> <td>${orders.orderNum }</td> <td>${orders.product.productName }</td> <td>${orders.product.productPrice }</td> <td>${orders.orderTimeStr }</td> <td class="text-center">${orders.orderStatusStr }</td> <td class="text-center"> <button type="button" class="btn bg-olive btn-xs">订单</button> <button type="button" class="btn bg-olive btn-xs" onclick="location.href='${pageContext.request.contextPath}/orders/findById.do?id=${orders.id}'">详情</button> <button type="button" class="btn bg-olive btn-xs">编辑</button> </td> </tr></c:forEach><div class="box-footer"> <div class="pull-left"> <div class="form-group form-inline"> 总共${pageInfo.pages}页,共${pageInfo.total}条数据。 每页 <select class="form-control" id="changePageSize" onchange="changePageSize()"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> 条 </div> </div> <div class="box-tools pull-right"> <ul class="pagination"> <li> <a href="${pageContext.request.contextPath}/orders/findAll.do?page=1&size=${pageInfo.pageSize}" aria-label="Previous">首页</a> </li> <li><a href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageInfo.pageNum-1}&size=${pageInfo.pageSize}">上一页</a></li> <c:forEach begin="1" end="${pageInfo.pages}" var="pageNum"> <li><a href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageNum}&size=${pageInfo.pageSize}">${pageNum}</a></li> </c:forEach> <li><a href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageInfo.pageNum+1}&size=${pageInfo.pageSize}">下一页</a></li> <li> <a href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageInfo.pages}&size=${pageInfo.pageSize}" aria-label="Next">尾页</a> </li> </ul> </div> </div><!--脚本--><script> function changePageSize() { //获取下拉框的值 var pageSize = $("#changePageSize").val(); //向服务器发送请求,改变没页显示条数 location.href = "${pageContext.request.contextPath}/orders/findAll.do?page=${pageInfo.pageNum}&size="+pageSize; }<script>