准备
项目结构
数据库
Book表
usertab表
jar包
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>test02</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value><!--要和applicationContext.xml名字一样,不然读取不到-->
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springmvcConfig.xml</param-value><!--要和applicationContext.xml名字一样,不然读取不到-->
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
db.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mydb
jdbc.username=root
jdbc.password=root
springmvcConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!--控制层的包写在SpringMvc.xml里面,其余的写在applicationContext.xml-->
<context:component-scan base-package="cn.itcast.controller"/>
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:default-servlet-handler/>
</beans>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:property-placeholder location="classpath:db.properties"/>
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="plugins">
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<props>
<prop key="dialect">mysql</prop>
<prop key="reasonable">true</prop>
</props>
</property>
</bean>
</property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.itcast.mapper" ></property>
</bean>
<context:component-scan base-package="cn.itcast.service"/>
</beans>
登录注册界面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="<%=basePath%>css/style.css" type="text/css" />
</head>
<body>
<section> <!-- 登录 -->
<div class="container">
<div class="user singinBx">
<div class="imgBx">
<img src="<%=basePath%>img/1.png" alt="">
</div>
<div class="formBx">
<!--form表单最关键注意action的地址是要传到那里去-->
<form action=" ${pageContext.request.contextPath}/user/loginCheck"
method="post">
<h2>登录</h2>
<!---最关键的:name属性 -->
<input type="text" name="uname" placeholder="用户名"> <input
type="password" name="password" placeholder="密码"> <input
type="submit" name="" value="登录">
<p class="signup">
没有账号?<a href="#" onclick="topggleForm();">注册</a>
</p>
</form>
</div>
</div>
<!-- 注册 -->
<div class="user singupBx">
<div class="formBx">
<form action="${pageContext.request.contextPath}/user/register"
method="post">
<h2>注册</h2>
<input type="text" name="uname" placeholder="用户名"> <input
type="password" name="password" placeholder="密码"> <input
type="password" name="" placeholder="再次输入密码"> <input
type="submit" name="" value="注册">
<p class="signup">
已有账号?<a href="#" onclick="topggleForm();">登录</a>
</p>
</form>
</div>
<div class="imgBx">
<img src="<%=basePath%>img/2.png" alt="">
</div>
</div>
</div>
</section>
<script type="text/javascript">
function topggleForm() {
var container = document.querySelector('.container');
container.classList.toggle('active');
}
</script>
</body>
</html>
实体层
pojo类
///Book类
public class Book {
private int bookid;
private String name;
private double price;
public int getBookid() {
return bookid;
}
public void setBookid(int bookid) {
this.bookid = bookid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public Book() {
super();
}
public Book(int bookid, String name, double price) {
super();
this.bookid = bookid;
this.name = name;
this.price = price;
}
@Override
public String toString() {
return "Book [bookid=" + bookid + ", name=" + name + ", price=" + price + "]";
}
}
User类
public class User {
private int id;
private String uname;
private String password;
public User() {
super();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public User(int id, String uname, String password) {
super();
this.id = id;
this.uname = uname;
this.password = password;
}
@Override
public String toString() {
return "User [id=" + id + ", uname=" + uname + ", password=" + password + "]";
}
}
mapper层
BookMapper.java
import java.util.List;
import org.springframework.stereotype.Repository;
import cn.itcast.pojo.Book;
@Repository
public interface BookMapper {
public List<Book> getAllBooks();
public List<Book> queryByBookid(int bookid);
public List<Book> queryByName(String name);
public int addBook(Book book);
public int deleteBook(int bookid);
public int updateBook(Book book);
}
BookMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.itcast.mapper.BookMapper">
<!-- 查询所有商品信息 -->
<select id="getAllBooks" resultType="cn.itcast.pojo.Book">
select * from book
</select>
<!-- 通过book编号模糊查询 -->
<select id="queryByBookid" parameterType="Integer"
resultType="cn.itcast.pojo.Book">
select * from book where bookid=#{_parameter}
</select>
<!-- 通过名字模糊查询 -->
<select id="queryByName" parameterType="String"
resultType="cn.itcast.pojo.Book">
select * from book where name like concat('%',#{_parameter},'%')
</select>
<!-- 添加书目 -->
<insert id="addBook" parameterType="cn.itcast.pojo.Book">
insert into book(name,price) values(#{name},#{price})
</insert>
<!-- 删除书目 -->
<delete id="deleteBook" parameterType="Integer">
delete from book where
bookid=#{_parameter}
</delete>
<!-- 修改书目 -->
<update id="updateBook" parameterType="cn.itcast.pojo.Book">
update book set
name=#{name},price=#{price} where bookid=#{bookid}
</update>
</mapper>
UserMapper.java
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import cn.itcast.pojo.User;
@Repository
public interface UserMapper {
User loginCheck(@Param("uname")String uname,@Param("password")String password);
int registerCheck(User user);
}
UserMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.itcast.mapper.UserMapper">
<select id="findAllUser" resultType="cn.itcast.pojo.User">
select * from usertab
</select>
<select id="loginCheck" parameterType="String" resultType="cn.itcast.pojo.User">
select * from usertab where uname =#{uname} and password=#{password}
</select>
<insert id="registerCheck" parameterType="cn.itcast.pojo.User">
insert into usertab(uid,uname,password) values(0,#{uname},#{password});
</insert>
</mapper>
service层
BookService.java
import java.util.List;
import cn.itcast.pojo.Book;
public interface BookService {
public List<Book> getAllBooks();
public List<Book> queryByBookid(int bookid);
public List<Book> queryByName(String name);
public int addBook(Book book);
public int deleteBook(int bookid);
public int updateBook(Book book);
}
BookServiceImpl.java
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.itcast.mapper.BookMapper;
import cn.itcast.pojo.Book;
@Service
public class BookServiceImpl implements BookService {
@Autowired
BookMapper bookMapper;
@Override
public List<Book> getAllBooks() {
return bookMapper.getAllBooks();
}
@Override
public List<Book> queryByBookid(int bookid) {
return bookMapper.queryByBookid(bookid);
}
@Override
public List<Book> queryByName(String name) {
return bookMapper.queryByName(name);
}
@Override
public int addBook(Book book) {
return bookMapper.addBook(book);
}
@Override
public int deleteBook(int bookid) {
return bookMapper.deleteBook(bookid);
}
@Override
public int updateBook(Book book) {
return bookMapper.updateBook(book);
}
}
UserService.java
import cn.itcast.pojo.User;
public interface UserService {
User loginCheck(String uname,String password);
int registerCheck(User user);
}
UserServiceImpl.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.itcast.mapper.UserMapper;
import cn.itcast.pojo.User;
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public int registerCheck(User user) {
return userMapper.registerCheck(user);
}
@Override
public User loginCheck(String uname, String password) {
return userMapper.loginCheck(uname, password);
}
}
控制层
UserController.java
package cn.itcast.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.itcast.pojo.User;
import cn.itcast.service.UserService;
@Controller
@RequestMapping("/user")
public class UserController{
@Autowired
private UserService userService;
@RequestMapping("/loginCheck")
public String checkLogin(HttpServletRequest req,String uname,String password) {
System.out.println("uname:"+uname);
System.out.println("password:"+password);
User user = userService.loginCheck(uname,password);
System.out.println(user);
HttpSession session=req.getSession();
session.setAttribute("u", user.getUname());
return "redirect:/book/getAllBook";
// return "forward:/book/getAllBook";
}
@RequestMapping("/register")
public String register(User u) {
int result=userService.registerCheck(u);
System.out.println("result"+result);
return "/registerSuccess";
}
}
BookController.java
package cn.itcast.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.itcast.pojo.Book;
import cn.itcast.service.BookService;
@Controller
@RequestMapping("/book")
public class BookController {
@Autowired
BookService bookService;
@RequestMapping("/queryByBookid")
public String queryBook(int bookid, Model model,@RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "4") int pageSize) {
if (pageNum == 0)
pageNum = 1;
PageHelper.startPage(pageNum, pageSize);// 开始分页,pageNum表示当前第几页,pageSize表示每页显示几条记录
List<Book> book = bookService.queryByBookid(bookid);
PageInfo<Book> p = new PageInfo<Book>(book);// 封装了分页后的信息
model.addAttribute("booklist", book);
model.addAttribute("pageinfo", p);
model.addAttribute("bookid", bookid);
return "queryInfoById";
}
@RequestMapping("/queryByBookName")
public String queryByName(String name, Model model, @RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "4") int pageSize) {
System.out.println("name:"+name);
if (pageNum == 0)
pageNum = 1;
PageHelper.startPage(pageNum, pageSize);// 开始分页,pageNum表示当前第几页,pageSize表示每页显示几条记录
List<Book> book = bookService.queryByName(name);// 查询所有用户的信息
PageInfo<Book> p = new PageInfo<Book>(book);// 封装了分页后的信息
model.addAttribute("booklist", book);
model.addAttribute("pageinfo", p);
model.addAttribute("name", name);
return "queryInfoByName";
}
@RequestMapping("/getAllBook")
public String getAllBook(Model model, @RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "4") int pageSize) {
PageHelper.startPage(pageNum, pageSize);// 开始分页,pageNum表示当前第几页,pageSize表示每页显示几条记录
List<Book> book = bookService.getAllBooks();// 查询所有用户的信息
PageInfo<Book> p = new PageInfo<Book>(book);// 封装了分页后的信息
model.addAttribute("booklist", book);
model.addAttribute("pageinfo", p);
System.out.println("信息:"+p);
return "bookInfo";
}
@RequestMapping("/toAddBook")
public String toAddBook() {/// 跳转到添加用户界面
return "addBook";
}
@RequestMapping("/addBook")
public String addBook(Book book) {/// 执行添加用户的功能
int result=bookService.addBook(book);
if(result>0) {
return "forward:getAllBook";
}else {
return "error";
}
}
@RequestMapping("/deleteBook")
public String deleteBook(int bookid) {
int result=bookService.deleteBook(bookid);
if(result>0) {
return "forward:getAllBook";
}else {
return "error";
}
}
@RequestMapping("/toUpdateBook")
public String toUpdateBook() {/// 跳转到修改用户界面
return "updateBook";
}
@RequestMapping("/updateBook")
public String updateUser(Book book) {
int result=bookService.updateBook(book);
if(result>0) {
return "forward:getAllBook";
}else {
return "error";
}
}
}
jsp
addBook.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加用户</title>
</head>
<body>
<center>
<form action="${pageContext.request.contextPath}/book/addBook"
method="post">
书名:<input type="text" name="name" /><br> 价格:<input type="text"
name="price" /><br> <input type="submit" value="提交" /><br>
</form>
</center>
</body>
</html>
bookInfo.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户界面</title>
<script type="text/javascript">
function del(bookid){
if(window.confirm("确定要删除吗?")){
console.log("跳转");
window.location.href="${pageContext.request.contextPath}/book/deleteBook?bookid="+bookid;
}else{
console.log("不删除");
}
}
</script>
</head>
<body>
欢迎你,<%=session.getAttribute("u") %>
<center>
<form method="post" action="${pageContext.request.contextPath}/book/queryByBookName">
<input type="text" name="name" placeholder="请输入关键字查询"/>
<input type="submit" value="提交"/>
<a href="${pageContext.request.contextPath}/book/toAddBook">添加</a>
</form><br>
<form method="post" action="${pageContext.request.contextPath}/book/queryByBookid">
<input type="text" name="bookid" placeholder="请输入书编号查询"/>
<input type="submit" value="提交"/>
</form><br>
<table border="1px" width="500px">
<tr>
<th>编号</th>
<th>书名</th>
<th>价格</th>
<th>操作</th>
</tr>
<c:choose>
<c:when test="${empty booklist}" >
<tr><td>没有查到相关信息!</td></tr>
</c:when>
<c:otherwise>
<c:forEach items="${booklist}" var="x">
<tr>
<td style="text-align: center;">${x.bookid}</td>
<td style="text-align: center;">${x.name}</td>
<td style="text-align: center;">${x.price}</td>
<!-- <td><a href="">修改</a>/<a href="${pageContext.request.contextPath}/user/deleteBook?uid=${x.bookid}">删除</a></td>-->
<td style="text-align: center;"><a href="${pageContext.request.contextPath}/book/toUpdateBook?bookid=${x.bookid}">修改</a>/<a href="javascript:del(${x.bookid})">删除</a></td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
第${pageinfo.pageNum }页/共${pageinfo.pages}页<br>
<a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${pageinfo.prePage}">上一页</a>
<c:forEach begin="1" end="${pageinfo.pages}" step="1" var="y">
<a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${y}">${y}</a>
</c:forEach>
<a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${pageinfo.nextPage}">下一页</a>
</center>
</body>
</html>
updateBook.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改用户</title>
</head>
<body>
<center>
<form action="${pageContext.request.contextPath}/book/updateBook"
method="post">
编号:<input type="text" name="bookid"
value="<%=request.getParameter("bookid")%>" readonly="readonly" /><br>
书名:<input type="text" name="name" /><br> 价格:<input type="text"
name="price" /><br>
<br> <input type="submit" value="提交" /><br>
</form>
</center>
</body>
</html>
queryInfoById.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>通过编号查询界面</title>
<script type="text/javascript">
function del(bookid){
if(window.confirm("确定要删除吗?")){
console.log("跳转");
window.location.href="${pageContext.request.contextPath}/book/deleteBook?bookid="+bookid;
}else{
console.log("不删除");
}
}
</script>
</head>
<body>
<center>
<table border="1px" width="500px">
<tr>
<th>书编号</th>
<th>书名</th>
<th>价格</th>
<th>操作</th>
</tr>
<c:choose>
<c:when test="${empty booklist}">
<tr><td style="text-align:center;">没有查到相关信息!</td></tr>
</c:when>
<c:otherwise>
<c:forEach items="${booklist}" var="x">
<tr>
<td style="text-align: center;">${x.bookid}</td>
<td style="text-align: center;">${x.name}</td>
<td style="text-align: center;">${x.price}</td>
<!-- <td><a href="">修改</a>/<a href="${pageContext.request.contextPath}/user/deleteBook?uid=${x.bookid}">删除</a></td>-->
<td style="text-align: center;"><a href="${pageContext.request.contextPath}/book/toUpdateBook?bookid=${x.bookid}">修改</a>/<a href="javascript:del(${x.bookid})">删除</a></td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
第${pageinfo.pageNum }页/共${pageinfo.pages }页<br>
<a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${pageinfo.prePage}">上一页</a>
<c:forEach begin="1" end="${pageinfo.pages }" step="1" var="y">
<a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${y}">${y}</a>
</c:forEach>
<a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${pageinfo.nextPage}">下一页</a>
</center>
</body>
</html>
queryInfoByName.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查询界面</title>
<script type="text/javascript">
function del(bookid){
if(window.confirm("确定要删除吗?")){
console.log("跳转");
window.location.href="${pageContext.request.contextPath}/book/deleteBook?bookid="+bookid;
}else{
console.log("不删除");
}
}
</script>
</head>
<body>
<center>
<table border="1px" width="500px">
<tr>
<th>书编号</th>
<th>书名</th>
<th>价格</th>
<th>操作</th>
</tr>
<c:choose>
<c:when test="${empty booklist}">
<tr><td style="text-align:center;">没有查到相关信息!</td></tr>
</c:when>
<c:otherwise>
<c:forEach items="${booklist}" var="x">
<tr>
<td style="text-align: center;">${x.bookid}</td>
<td style="text-align: center;">${x.name}</td>
<td style="text-align: center;">${x.price}</td>
<!-- <td><a href="">修改</a>/<a href="${pageContext.request.contextPath}/user/deleteBook?uid=${x.bookid}">删除</a></td>-->
<td style="text-align: center;"><a href="${pageContext.request.contextPath}/book/toUpdateBook?bookid=${x.bookid}">修改</a>/<a href="javascript:del(${x.bookid})">删除</a></td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
第${pageinfo.pageNum }页/共${pageinfo.pages }页<br>
<a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${pageinfo.prePage}">上一页</a>
<c:forEach begin="1" end="${pageinfo.pages }" step="1" var="y">
<a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${y}">${y}</a>
</c:forEach>
<a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${pageinfo.nextPage}">下一页</a>
</center>
</body>
</html>
参考链接:https://wwp.lanzouo.com/iCISwxves7i
总结
奋斗的青春最美丽!希望期末javaEE一遍过!加油!