SSM集成开发书籍查询
开发工具:IDEA-maven 、jdk1.8、Tomcat
一、开发环境的搭建及依赖的导入
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>ssmbuild</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- 依赖 :Junit 数据库驱动,连接池,servlet jsp mybatis mybatis-spring spring -->
<dependencies>
<!-- 测试单元 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
</dependency>
<!-- 数据库连接池 c3p0或者dbcp-->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.5</version>
</dependency>
<!-- 数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
<!-- servlet -jsp -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<!-- mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.6</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.1</version>
</dependency>
<!-- spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.3</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
</dependencies>
<!-- 静态资源导出问题 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
</excludes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
</project>
二、maven项目增加web的支持[外链图片
三、创建MVC的三层架构
3.1、controller层
package com.example.controller;
import com.example.pojo.Books;
import com.example.service.BookService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import java.awt.print.Book;
import java.util.List;
@Controller
@RequestMapping("/book")
public class BookController {
//controller 调 service层
@Autowired
@Qualifier("BookServiceImp")
private BookService bookService;
//查询全部的书籍 并且返回到一个书籍展示页面
@RequestMapping("/allBook")
// @RequestBody("")
public String list(Model model){
List<Books> list = bookService.queryAllBook();
for (Books listquery: list) {
System.out.println(listquery);
}
// System.out.println(list);
model.addAttribute("list",list);
return "allBook";
}
//跳转到增加页面
@RequestMapping("/toAddBook")
public String toAddBook(){
return "addBook";
}
//添加书籍的请求
//业务层调service层
@RequestMapping("/addBook")
public String addBook(Books books){
System.out.println("addBook"+books);
bookService.addBook(books);
return "redirect:/book/allBook"; //重定向到allBook请求
}
//跳转到修改页面
@RequestMapping("/toUpdateBook")
public String toUpdateBook(int id,Model model){
Books books = bookService.queryBookById(id);
// System.out.println("toUpdateBook"+books);
model.addAttribute("qBooks",books); //封装并传到前端
return "updateBook";
}
//修改书籍
@RequestMapping("/updateBook")
public String updateBook(Books books){
// System.out.println("updateBook"+books);
bookService.updateBook(books);
return "redirect:/book/allBook";
}
@RequestMapping("/toDeleteBook")
public String toDeleteBook(int id,Model model){
Books books = bookService.queryBookById(id);
model.addAttribute("dBooks",books);
return "deleteBook";
}
//删除书籍
@RequestMapping("/deleteBook")
public String toDeleteBookById(int id, Model model){
bookService.deleteBookById(id);
return "redirect:/book/allBook"; //重定向到查询所有书籍页面
}
//查询书籍
@RequestMapping("/queryBook")
public String queryBook(String queryBookName,Model model){
// System.out.println("queryBookName:"+queryBookName);
List<Books> books = bookService.queryBook(queryBookName);
model.addAttribute("queryBookName",books);//封装并传到前端
// System.out.println("s==>>>"+books);
return "queryBook"; //跳转到queryBook页面
}
}
3.2、Dao层(查询数据库 注解实现)
package com.example.dao;
import com.example.pojo.Books;
import org.apache.ibatis.annotations.*;
import java.util.List;
public interface BookMapper {
@Insert("insert into ssmbuild.books(bookID,bookName,bookCounts,detail) values(#{books.bookID},#{books.bookName},#{books.bookCounts},#{books.detail})")
int addBook(@Param("books")Books books);
@Select("select * from ssmbuild.books where books.bookName = #{books.queryBookName}")
List<Books> queryBook(String queryBook);
@Delete("delete from ssmbuild.books where books.bookID = #{id}")
int deleteBookById(@Param("id")int id);
@Update("update ssmbuild.books set books.bookID=#{books.bookID},bookName = #{books.bookName},bookCounts = #{books.bookCounts},detail = #{books.detail} where books.bookID = #{books.bookID}" )
int updateBook(@Param("books")Books books);
@Select("select * from ssmbuild.books where books.bookID = #{id}")
Books queryBookById(@Param("id")int id);
@Select("select * from ssmbuild.books")
List<Books> queryAllBook();
}
3.2.1、实体类
package com.example.pojo;
import lombok.AllArgsConstructor;//全参构造
import lombok.Data;//geter/setter方法
import lombok.NoArgsConstructor;//无参构造
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Books {
private int bookID;
private String bookName;
private int bookCounts;
private String detail;
}
3.3、service层
package com.example.service;
import com.example.pojo.Books;
import java.util.List;
public interface BookService {
int addBook(Books books);
int deleteBookById(int id);
int updateBook(Books books);
Books queryBookById(int id);
List<Books> queryBook(String queryBook);
List<Books> queryAllBook();
}
3.3.1、service层接口实现
package com.example.service;
import com.example.dao.BookMapper;
import com.example.pojo.Books;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class BookServiceImp implements BookService {
//service层调用dao层 组合Dao
// @Autowired
private BookMapper bookMapper;
public void setBookMapper(BookMapper bookMapper)
{
this.bookMapper = bookMapper;
}
@Override
public int addBook(Books books) {
return bookMapper.addBook(books);
}
@Override
public int deleteBookById(int id) {
return bookMapper.deleteBookById(id);
}
@Override
public int updateBook(Books books) {
return bookMapper.updateBook(books);
}
@Override
public Books queryBookById(int id) {
return bookMapper.queryBookById(id);
}
@Override
public List<Books> queryBook(String queryBook) {
return bookMapper.queryBook(queryBook);
}
@Override
public List<Books> queryAllBook() {
return bookMapper.queryAllBook();
}
}
四、SSM配置的xml文件
4.1、Spring的配置
<!-- applicationContext.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" default-autowire="byName"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="classpath:spring-dao.xml"/>
<import resource="classpath:spring-service.xml"/>
<import resource="classpath:spring-mvc.xml"/>
</beans>
4.2、Mybatis的配置
<!-- mybatis-config.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!-- properties配置数据库 -->
<properties resource="database.properties"/>
<!-- 别名 -->
<typeAliases>
<package name="com.example.pojo"/>
</typeAliases>
<environments default="development">
<environment id="development">
<!-- 事务管理器 -->
<transactionManager type="JDBC"></transactionManager>
<!-- 数据源 -->
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>
</environment>
</environments>
</configuration>
<!-- database.properties -->
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC
jdbc.username=root
jdbc.password=root
4.3、SpringMVC的三层架构
<!-- spring-dao.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- Spring配置文件的DTD定义-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http="http://www.springframework.org/schema/c"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<!-- 1.关联数据库配置文件 -->
<context:property-placeholder location="classpath:database.properties"/>
<!-- 2.连接池
dbcp:半自动化操作 不能自动连接
c3p0:自动化操作(自动化的加载配置文件,并且可以自动设置到对象在中)
druid:
hikari(springboot 2.0):
-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- c3p0连接池的私有属性 -->
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<!-- 关闭连接后不自动提交(commit) -->
<property name="autoCommitOnClose" value="false"/>
<!-- 获取连接超时时间 -->
<property name="checkoutTimeout" value="10000"/>
<!-- 当获取连接失败重试次数 -->
<property name="acquireRetryAttempts" value="2"/>
</bean>
<!-- 3.sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
<!-- 配置dao接口扫描包,动态实现Dao接口可以注入到Spring容器中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 注入sqlSessionFactory -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!-- 要扫描的dao包 -->
<property name="basePackage" value="com.example.dao"/>
</bean>
</beans>
<!-- spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">
<!-- 1.注解驱动 -->
<mvc:annotation-driven/>
<!-- 2.静态资源过滤-->
<mvc:default-servlet-handler/>
<!-- 3.扫描包:controller-->
<context:component-scan base-package="com.example.controller"/>
<!-- 4.视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 前缀 -->
<property name="prefix" value="/WEB-INF/jsp/"/>
<!-- 后缀 -->
<property name="suffix" value=".jsp"/>
</bean>
</beans>
<!-- spring-service.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- Spring配置文件的DTD定义-->
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 1.扫描service下的包 -->
<context:component-scan base-package="com.example.service"/>
<!-- 2.将所有的业务类,注入到spring 可以通过配置或者注解实现 -->
<bean id="BookServiceImp" class="com.example.service.BookServiceImp">
<property name="bookMapper" ref="bookMapper"/>
</bean>
<!-- 3.声明式事务配置 -->
<bean id="TransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
五、web支持配置
5.1、首页设计
<%--
Created by IntelliJ IDEA.
User: 19175
Date: 2021/1/21
Time: 16:20
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>首页</title>
<style>
.box{
width:100px;
height: auto;
background-color:pink;
position: absolute;
left:650px;
top:350px;
}
body{
background-color: #b9def0;
}
</style>
</head>
<body>
<div class="box">
<h3>
<a style="text-decoration-line: none" href="${pageContext.request.contextPath}/book/allBook">查询书籍</a>
</h3>
</div>
</body>
</html>
5.2、增删改查页面
<!-- 增加书籍 -->
<%--
Created by IntelliJ IDEA.
User: 19175
Date: 2021/1/24
Time: 16:44
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta charset="utf-8">
<title>图书管理系统</title>
<%-- <link rel="stylesheet" type="text/css" href="../css/index.css"/>--%>
<link href="http://cdn.static.runoob.com/libs/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>
<form action="${pageContext.request.contextPath}/book/addBook" method="post">
<%-- <div class="form-group" >--%>
<%-- <label for="bkId">书籍编号:</label>--%>
<%-- <input type="text" name="bookId" class="form-control" id="bkId" required>--%>
<%-- </div>--%>
<div class="form-group" >
<label for="bkID">书籍编号:</label>
<input type="text" name="bookID" class="form-control" id="bkID" required>
</div>
<div class="form-group" >
<label for="bkName">书籍名称:</label>
<input type="text" name="bookName" class="form-control" id="bkName" required>
</div>
<div class="form-group" >
<label for="bkCounts">书籍数量:</label>
<input type="text" name="bookCounts" class="form-control" id="bkCounts" required>
</div>
<div class="form-group" >
<label for="bkDetail">书籍描述:</label>
<input type="text" name="detail" class="form-control" id="bkDetail" required>
</div>
<div class="form-group" >
<input type="submit" class="form-control" value="添加">
</div>
</form>
</div>
</div>
</body>
</html>
<!-- 删除书籍 -->
<%--<jsp:useBean id="qBooks" scope="request" type="com.example.pojo.Books"/>--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta charset="utf-8">
<title>图书管理系统</title>
<%-- <link rel="stylesheet" type="text/css" href="../css/index.css"/>--%>
<link href="http://cdn.static.runoob.com/libs/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>
<form action="${pageContext.request.contextPath}/book/deleteBook" method="post">
<%-- <div class="form-group" >--%>
<%-- <label for="bkId">书籍编号:</label>--%>
<%-- <input type="text" name="bookId" class="form-control" id="bkId" required>--%>
<%-- </div>--%>
<div class="form-group" >
<label for="bkID">书籍编号:</label>
<input type="text" name="bookID" class="form-control" id="bkID" value="${dBooks.bookID}" required>
</div>
<div class="form-group" >
<label for="bkName">书籍名称:</label>
<input type="text" name="bookName" class="form-control" id="bkName" value="${dBooks.bookName}" required>
</div>
<div class="form-group" >
<label for="bkCounts">书籍数量:</label>
<input type="text" name="bookCounts" class="form-control" id="bkCounts" value="${dBooks.bookCounts}" required>
</div>
<div class="form-group" >
<label for="bkDetail">书籍描述:</label>
<input type="text" name="detail" class="form-control" id="bkDetail" value="${dBooks.detail}" required>
</div>
<div class="form-group" >
<input type="submit" class="form-control" value="删除">
</div>
</form>
</div>
</div>
</body>
</html>
<!-- 修改书籍信息 -->
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta charset="utf-8">
<title>图书管理系统</title>
<%-- <link rel="stylesheet" type="text/css" href="../css/index.css"/>--%>
<link href="http://cdn.static.runoob.com/libs/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>
<form action="${pageContext.request.contextPath}/book/updateBook" method="post">
<%-- <div class="form-group" >--%>
<%-- <label for="bkId">书籍编号:</label>--%>
<%-- <input type="text" name="bookId" class="form-control" id="bkId" required>--%>
<%-- </div>--%>
<div class="form-group" >
<label for="bkID">书籍编号:</label>
<input type="text" name="bookID" class="form-control" id="bkID" value="${qBooks.bookID}" required>
</div>
<div class="form-group" >
<label for="bkName">书籍名称:</label>
<input type="text" name="bookName" class="form-control" id="bkName" value="${qBooks.bookName}" required>
</div>
<div class="form-group" >
<label for="bkCounts">书籍数量:</label>
<input type="text" name="bookCounts" class="form-control" id="bkCounts" value="${qBooks.bookCounts}" required>
</div>
<div class="form-group" >
<label for="bkDetail">书籍描述:</label>
<input type="text" name="detail" class="form-control" id="bkDetail" value="${qBooks.detail}" required>
</div>
<div class="form-group" >
<input type="submit" class="form-control" value="修改">
</div>
</form>
</div>
</div>
</body>
</html>
<!-- 查询一本书籍信息 -->
<%--
Created by IntelliJ IDEA.
User: 19175
Date: 2021/1/21
Time: 16:35
To change this template use File | Settings | File Templates.
--%>
<%--<%@ page contentType="text/html;charset=GBK" %>--%>
<%--<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="utf-8">
<title>图书管理系统</title>
<%-- <link rel="stylesheet" type="text/css" href="../css/index.css"/>--%>
<%-- <link rel="stylesheet" type="text/css" href="bootstrap/bootstrap-3.3.7-dist/css/bootstrap.css"/>--%>
<link href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- <div id="" class="div_top">
<img src="../img/三峡学院图标.jpg" class="img_css" >
<h1 class="h1_css"><a href="https://www.baidu.com" target="_blank">图书管理系统</a></h1>
</div>
<div class="div_left">
</div>
<div class="div_right">
</div> -->
<style>
.query{
position: absolute;
top: 3px;
left: 391px
}
</style>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="page-header">
<h1>
<small>书籍查询信息</small>
</h1>
</div>
</div>
<div class="row">
<div class="col-md-4 column">
<a class="btn-primary" href="${pageContext.request.contextPath}/book/toAddBook" target="_blank">新增信息</a>
</div>
<div class="col-md-4 column">
<%-- 查询书籍--%>
<form action="${pageContext.request.contextPath}/book/queryBook" method="post">
<span>
<input type="text" placeholder="请输入查询书籍名称:" class="form-control" name="queryBookName">
<input type="submit" value="查询" class="query">
</span>
</form>
</div>
</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>
</tr>
</thead>
<!-- 从数据库查询出来的信息,返回到前端显示 -->
<tbody>
<c:forEach var="book" items = "${queryBookName}">
<tr>
<td>${book.bookID}</td>
<td>${book.bookName}</td>
<td>${book.bookCounts}</td>
<td>${book.detail}</td>
<td>
<a href="${pageContext.request.contextPath}/book/toUpdateBook?id=${book.bookID}">修改</a>
|
<a href="${pageContext.request.contextPath}/book/deleteBook?id=${book.bookID}">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
<!-- 查询全部书籍信息 -->
<%--
Created by IntelliJ IDEA.
User: 19175
Date: 2021/1/21
Time: 16:35
To change this template use File | Settings | File Templates.
--%>
<%--<%@ page contentType="text/html;charset=GBK" %>--%>
<%--<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta charset="utf-8">
<title>书籍管理系统</title>
<%-- <link rel="stylesheet" type="text/css" href="../css/index.css"/>--%>
<%-- <link rel="stylesheet" type="text/css" href="bootstrap/bootstrap-3.3.7-dist/css/bootstrap.css"/>--%>
<link href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<style>
.query{
position: absolute;
top: 3px;
left: 391px
}
</style>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="page-header">
<h1>
<small>书籍列表----显示所有书籍</small>
</h1>
</div>
</div>
<div class="row">
<div class="col-md-4 column">
<a class="btn-primary" href="${pageContext.request.contextPath}/book/toAddBook" target="_blank">新增信息</a>
</div>
<div class="col-md-4 column">
<%-- 查询书籍--%>
<form action="${pageContext.request.contextPath}/book/queryBook" method="post">
<span>
<input type="text" placeholder="请输入查询书籍名称:" class="form-control" name="queryBookName">
<input type="submit" value="查询" class="query">
</span>
</form>
</div>
</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>
</tr>
</thead>
<!-- 从数据库查询出来的信息,返回到前端显示 -->
<tbody>
<c:forEach var="book" items="${list}">
<tr>
<td>${book.bookID}</td>
<td>${book.bookName}</td>
<td>${book.bookCounts}</td>
<td>${book.detail}</td>
<td>
<a href="${pageContext.request.contextPath}/book/toUpdateBook?id=${book.bookID}">修改</a>
|
<a href="${pageContext.request.contextPath}/book/deleteBook?id=${book.bookID}">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
六、页面展示