分页查询
实现分页
步骤
确定每页显示的数据量
确定分页显示所需的总页数
编写sql查询语句,实现数据查询
1)limit分页公式 (1)limit分页公式:curPage是当前第几页;pageSize是一页多少条记录 limit (curPage-1)*pageSize,pageSize (2)用的地方:sql语句中 select * from student limit(curPage-1)*pageSize,pageSize; 2)总页数公式 (1)总页数公式:totalRecord是总记录数;pageSize是一页分多少条记录 int totalPageNum = (totalRecord +pageSize - 1) / pageSize; (3)查询总条数:totalRecord是总记录数 SELECT COUNT(*) FROM tablename
<li class="<%=curPage%pageSize==1?"active":"" %>"><a name="cp"><%=curPage/5==0?1:(curPage-1)/5*5+1%><span class="sr-only"></span></a></li>
JavaBean
概述
就是一个Java类
作用
封装业务逻辑 封装数据
jsp:useBean标签
装载一个将在JSP页面中使用的JavaBean
<jsp:useBean id="name" class="package.class" scope="scope" >include指令
示例
静态包含,将被包含页面的内容包含进来。先包含,再处理
<%@ include file="loginControl.jsp" %> jsp:include标签
动态包含,将被包含页面的结果包含进来。先处理,再包含
<jsp:include page="URL">jsp:forward标签
类似转发
<jsp:forward page="URL">base标签
作用 a标签就不会另开页面去跳转了,就在iframe展示
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <base target="fram"> </head> <body> <p><a href="//www.taobao.com/">淘宝</a> </p> <iframe name="fram" src="http://www.baidu.com" width="500px" height="500px"></iframe> </body> </html>
代码实现
<%@page import="kgc.pojo.Student"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<jsp:useBean id="studentService" class="kgc.service.StudentService"></jsp:useBean>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
html, body {
height: 100%;
overflow: auto;
}
body {
background: url(ac.jpg) top left;
background-size: 100%;
}
span {
color: red;
font-size: 30px;
}
#a {
font-size: 20px;
}
table{
/* 设置了这个属性,其余所有td都是相同的宽度。
这样操作之后,table是宽度固定了,但是里面的文章如果很长,文字会覆盖 */
table-layout:fixed ;
}
td{
/* 自动换行就好了 */
/* word-wrap:break-word; */
width:10px;height:11px
}
</style>
</head>
<%
int sumPage=12 ;
String cpStr = request.getParameter("currentPage");
int currentPage=(cpStr==null?1:Integer.parseInt(cpStr));
List<Student> lists = studentService.queryLimit(currentPage, sumPage);
int CountPage=studentService.queryAllNumber();
%>
<body>
<div >
<!-- div width 100等于 左靠齐 -->
<div style="margin: 0px auto; width:100%" >
您的手机号<%=request.getParameter("phone")%>
您的密码<%=request.getParameter("loginPwd")%>
<div style="width: 100%; text-align: center">
<h1 style="color: blue">欢迎进入学生档案</h1>
</div>
<!-- width 1000等于表格宽度 -->
<table border="1px" cellspacing="0px" width="1500" height="150">
<tr>
<th colspan="5">学生信息</th>
</tr>
<tr>
<th>学生学号</th>
<th>学生姓名</th>
<th>学生手机</th>
<th>学生地址</th>
<th>操作</th>
</tr>
<%
for (Student list : lists) {
%>
<tr>
<td style="display: none"><%=list.getId() %></td>
<td><%=list.getStudentNo()%> </td>
<td><%=list.getStudentName()%> </td>
<td><%=list.getPhone()%></td>
<td><%=list.getAddress()%></td>
<td><a href="delete.jsp?id=<%=list.getId() %>">删除</a></td>
</tr>
<%
}
%>
</table>
<a href="Welcome.jsp?currentPage=1">首页</a>
<!-- 使用三目运算符 比较 -->
<a href="Welcome.jsp?currentPage=<%=CountPage%sumPage!=0?CountPage/sumPage+1:CountPage/sumPage%>">尾页</a>
<a href="Welcome.jsp?currentPage=<%=currentPage!=1?currentPage-1:1%>">上一页</a>
<a href="Welcome.jsp?currentPage=<%=currentPage!=(CountPage%sumPage!=0?CountPage/sumPage+1:CountPage/sumPage)?currentPage+1:currentPage%>">下一页</a>
<br><br>
<div style="margin: 0px auto; width:20%" >
<h1 style="color: blue">修改学生信息</h1>
<form action="changeid.jsp" method="get" >
<div>
<span>请输入学生ID</span><input type="text" name="studentNoone" />
</div>
<br> <br> <input type="submit" value="点击修改"
style="font-size: 20px" />
</form>
<a href="addOnehundred.jsp">点击增加一百个用户</a>
</div>
</div>
</div>
</body>
</html>