<%@ page import="model.stu" %>
<%@ page import="java.util.List" %>
<%@ page import="dao.JdbcTool" %>
<%@ page import="dao.JdbcTools" %><%--
Created by IntelliJ IDEA.
User: 86173
Date: 2024/8/1
Time: 15:51
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<%-- 前端数据美化测试赛css js都要写到head里面--%>
<title>学生记录分页演示</title>
<style>
table,tr,th,td{
border-collapse: collapse;
border: solid 1px red;
margin: 0 auto;
width: 800px;
}
</style>
</head>
<body>
<%--页码跳转--%>
<% List<stu> stulist = JdbcTool.select("select * from stu ", stu.class);
System.out.println("stulist = " + stulist);
%>
<%
int curpage;
if (request.getParameter("curpage")==null){
curpage=1;
}else {
curpage = Integer.valueOf(request.getParameter("curpage"));
}
//1设定每一页的记录数
int pageSize=2;
// 2计算总的记录数
int recordCoundTotal=stulist.size();
// 3分页的总页数
// 向上取整
int pageCount = (int) Math.ceil(recordCoundTotal * 1.0 / pageSize);
//采用三目运算,进行向上取整
// int pageCount = recordCountTotal % pageSize==0?recordCountTotal / pageSize:recordCountTotal / pageSize+1;
System.out.println("pageCount = " + pageCount);
// 构建sql语句查询当前页的记录数
String sql="select * from stu limit "+(curpage-1)*pageSize+","+pageSize;
// 获取当前页数据
List<stu> stuList1 = JdbcTools.queryBeanList(sql, stu.class);
%>
<h1>学生信息管理展示</h1>
<table cellpadding="3" cellspacing="0" border="1" align="center">
<tr>
<th>ID</th>
<th>姓名</th>
<th>年龄</th>
<th>操作1</th>
<th>操作2</th>
</tr>
<%
for (int i = 0; i < stuList1.size(); i++) {
%>
<tr>
<td>
<%-- 等于号是给值操作--%>
<%=stuList1.get(i).getId()%>
</td>
<td>
<%-- 等于号是给值操作--%>
<%=stuList1.get(i).getName()%>
</td>
<td>
<%-- 等于号是给值操作--%>
<%=stuList1.get(i).getAge()%>
</td>
<td><a href="delone?Sno=<%=stulist.get(i).getId()%>" onclick="return confirm('确认删除吗?');">删除</a></td>
<td><a href="updateshow?id=<%=stulist.get(i).getId()%>">更新</a></td>
</tr>
<%
}
%>
<%
if (curpage == 1) {
%>
<span class="nice">首页</span>
<span>上一页</span>
<a href="showlist4.jsp?curpage=<%=curpage+1%>">下一页</a>
<a href="showlist4.jsp?curpage=<%=pageCount%>">尾页</a>
<%
} else if (curpage == pageCount) {
%>
<a href="showlist4.jsp?curpage=1">首页</a>
<a href="showlist4.jsp?curpage=<%=curpage-1%>">上一页</a>
<span class="nice">下一页</span>
<span>尾页</span>
<%
} else {
%>
<a href="showlist4.jsp?curpage=1">首页</a>
<a href="showlist4.jsp?curpage=<%=curpage-1%>">上一页</a>
<a href="showlist4.jsp?curpage=<%=curpage+1%>">下一页</a>
<a href="showlist4.jsp?curpage=<%=pageCount%>">尾页</a>
<%
}
%>
</body>
</html>
错误小结
herf里面双引号,需要注意好
<% %>在前端写java语句后端的于语句,要进行包装起来
向上取整