标签:col tag title cto page reac new list tis
通过搭建ssm框架,然后通过mybatis的分页插件pagehelper-5.1.2.jar和jsqlparser-0.9.7.jar进行分页查询。
index.jsp
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <a href="list">分页查询</a> </body> </html>
list.jsp
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>Insert title here</title> 9 </head> 10 <body> 11 <center> 12 <table width="200" border="1"> 13 <tr> 14 <th scope="col">ID</th> 15 <th scope="col">姓名</th> 16 <th scope="col">性别</th> 17 <th scope="col">城市</th> 18 </tr> 19 <c:forEach items="${pageInfo.list}" var="user"> 20 <tr> 21 <td>${user.id}</td> 22 <td>${user.username}</td> 23 <td>${user.sex}</td> 24 <td>${user.city}</td> 25 </tr> 26 </c:forEach> 27 </table> 28 29 <p>当前 ${pageInfo.pageNum}页,总${pageInfo.pages} 页,总 30 ${pageInfo.total} 条记录 31 32 </p> 33 34 <a href="list?pageNo=${pageInfo.firstPage}">第一页</a> 35 36 <c:if test="${pageInfo.hasPreviousPage}"> 37 <a href="list?pageNo=${pageInfo.pageNum-1}">上一页</a> 38 </c:if> 39 40 <c:if test="${pageInfo.hasNextPage}"> 41 <a href="list?pageNo=${pageInfo.pageNum+1}">下一页</a> 42 </c:if> 43 44 <a href="list?pageNo=${pageInfo.lastPage}">最后页</a> 45 </center> 46 </body> 47 </html>
UserController.java
1 package cn.edu.hnzj.controller; 2 3 import java.util.List; 4 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.stereotype.Controller; 7 import org.springframework.ui.ModelMap; 8 import org.springframework.web.bind.annotation.RequestMapping; 9 import org.springframework.web.bind.annotation.RequestMethod; 10 import org.springframework.web.bind.annotation.RequestParam; 11 12 import com.github.pagehelper.PageHelper; 13 import com.github.pagehelper.PageInfo; 14 15 import cn.edu.hnzj.po.User; 16 import cn.edu.hnzj.service.UserService; 17 18 @Controller 19 public class UserController { 20 @Autowired 21 private UserService pageService; 22 23 /** 24 * 分页查询 25 */ 26 @RequestMapping(value="/list",method=RequestMethod.GET) 27 public String pageList(ModelMap map,@RequestParam(defaultValue="1",required=true,value="pageNo") Integer pageNo){ 28 Integer pageSize=4;//每页显示记录数 29 //分页查询 30 PageHelper.startPage(pageNo, pageSize); 31 List<User> userList = pageService.list();//获取所有用户信息 32 PageInfo<User> pageInfo=new PageInfo<User>(userList); 33 map.addAttribute("pageInfo", pageInfo); 34 35 return "list"; 36 } 37 }
标签:col tag title cto page reac new list tis
原文地址:https://www.cnblogs.com/hnzj/p/14903853.html