一、修改书籍
1.1、allBook.jsp
1.2、BookController类
//跳转到修改页面
@RequestMapping("/toUpdate")
public String toUpdatePage(int id , Model model){
Books books = bookService.queryBookById(id);
model.addAttribute("QBook",books);
return "updateBook";
}
//修改书籍
@RequestMapping("/updateBook")
public String updateBook(Books books){
bookService.updateBook(books);
return "redirect:/book/allBook";
}
1.3、updateBook.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改书籍</title>
<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row clearfix">
<div class="col-md-12" column>
<div class="page-header">
<h1>
<small>修改书籍</small>
</h1>
</div>
</div>
</div>
<form action="${pageContext.request.contextPath}/book/updateBook" method="post">
<%--出现的问题:我们提交了修改SQL请求,但是修改失败,初次考虑,是事务问题,配置完毕事务,依旧失败--%>
<%--看一下SQL语句,能否执行成功:SQL执行失败,修改未完成--%>
<%--前端传递隐藏域--%>
<input type="hidden" name="bookID" value="${QBook.bookID}">
<div class="form-group">
<label for="bkname">书籍名称:</label>
<input type="text" name="bookName" class="form-control" id="bkname" value="${QBook.bookName}" required>
</div>
<div class="form-group">
<label for="bkname2">书籍数量:</label>
<input type="text" name="bookCounts" class="form-control" id="bkname2" value="${QBook.bookCounts}" required>
</div>
<div class="form-group">
<label for="bkname3">书籍描述:</label>
<input type="text" name="detail" class="form-control" id="bkname3" value="${QBook.detail}" required>
</div>
<div class="form-group">
<input type="submit" class="form-control" value="修改">
</div>
</form>
</div>
</body>
</html>
效果:
二、删除书籍
2.1、allBook.jsp同上
2.2、BookController类
//删除书籍
@RequestMapping("/deleteBook")
public String deleteBook(int id){
bookService.deleteBookById(id);
return "redirect:/book/allBook";
}