整合SSM框架(2)
目录
一、查询全部书籍
1.1 编写BookController类
1.2 编写首页(index.jsp)
1.3 展示全部书籍页面(allBook.jsp)
二、添加书籍
2.1 跳转到添加书籍页面
2.1.1 allBook.jsp
2.1.2 BookController
2.2 添加书籍
2.2.1 addBook.jsp
2.2.2 BookController
三、修改书籍
3.1 跳转到修改书记页面
3.1.1 allBook.jsp
3.1.2 BookController
3.2 修改书籍
3.2.1 updateBook.jsp
3.2.2 BookController
四、删除书籍
4.1 allBook.jsp
4.2 BookController
【Controller和视图层编写】
一、查询全部书籍
1.1 编写BookController类
1.2 编写首页(index.jsp)
首页为入口,可以进入查询全部书籍的页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>首页</title>
<style>
a{
text-decoration: none;
color: black;
font-size: 18px;
}
h3{
width: 180px;
height: 38px;
margin: 100px auto;
text-align: center;
line-height: 38px;
background: deepskyblue;
border-radius: 5px;
}
</style>
</head>
<body>
<h3>
<a href="${pageContext.request.contextPath}/book/allBooks">进入书籍页面</a>
</h3>
</body>
</html>
1.3 展示全部书籍页面(allBook.jsp)
(后续将增删改操作都加进展示全部书籍的页面)
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>书籍列表</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- 引入 Bootstrap -->
<link href="https://cdn.bootcss.com/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>
<div class="row">
<div class="col-md-4 column">
<a class="btn btn-primary" href="${pageContext.request.contextPath}/book/toAddBook">新增</a>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>书籍编号</th>
<th>书籍名字</th>
<th>书籍数量</th>
<th>书籍详情</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<c:forEach var="book" items="${requestScope.get('list')}">
<tr>
<td>${book.getBookID()}</td>
<td>${book.getBookName()}</td>
<td>${book.getBookCounts()}</td>
<td>${book.getDetail()}</td>
<td>
<a href="${pageContext.request.contextPath}/book/toUpdateBook?id=${book.getBookID()}">更改</a> |
<a href="${pageContext.request.contextPath}/book/deleteBook/${book.getBookID()}">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
二、添加书籍
2.1 跳转到添加书籍页面
2.1.1 allBook.jsp
2.1.2 BookController
2.2 添加书籍
2.2.1 addBook.jsp
2.2.2 BookController