0%

【Spring】Spring-MVC-项目实战

Spring-MVC-项目实战笔记

目的

  • 为了记录一些没必要反复去写的配置而存在
  • 从零构建项目

技术栈

  • Spring
  • SpringMVC
  • Mybatis
  • MySql
  • Jsp
  • Bootstrap
  • Aop
  • Maven
  • Intellij IDEA

….

SSM架构原理

需求

制作一个具有增删该查的初级表单功能

数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
CREATE DATABASE `ssmbuild`;

USE `ssmbuild`;

CREATE TABLE `books`
(
`bookID` INT(10) NOT NULL AUTO_INCREMENT COMMENT '书id',
`bookName` VARCHAR(100) NOT NULL COMMENT '书名',
`bookCounts` INT(11) NOT NULL COMMENT '数量',
`detail` VARCHAR(200) NOT NULL COMMENT '描述',
KEY `bookID` (`bookID`)
) ENGINE = INNODB
DEFAULT CHARSET = utf8;

INSERT INTO ssmbuild.books (bookID, bookName, bookCounts, detail)
VALUES (1, 'Java', 111, '从入门到放弃');
INSERT INTO ssmbuild.books (bookID, bookName, bookCounts, detail)
VALUES (2, 'MySQL', 10, '从删库到跑路');
INSERT INTO ssmbuild.books (bookID, bookName, bookCounts, detail)
VALUES (3, 'Linux', 5, '从进门到进牢');

新建项目

选择Maven直接新建

改好路径,项目名称,artifactId

为项目新增Web框架

新建如下标红包与文件夹

现在你已经有了一个空项目了,接下来开始配置它

Maven

依赖

引入各技术栈的依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<dependencies>
<!-- springframework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.12.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.12.RELEASE</version>
</dependency>
<!--Aop-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.13</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.7</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.2</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!-- jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.12.RELEASE</version>
</dependency>
<!-- 数据连接池 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<!-- servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Jsp -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
</dependency>

<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

Maven资源处理

若无此配置,mybatis的xml文件无法正常打包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>

阿里镜像

增速jar包加载

1
2
3
4
5
6
7
8
9
10
<repositories>
<repository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>

-

1
2
3
4
5
6
7
8
9
10
11
12
13
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

POJO/数据实体类

对应表books
Books.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.wx.pojo;

public class Books {

private int bookId;
private String bookName;
private int bookCounts;
private String detail;

public Books() { }

public Books(int bookId, String bookName, int bookCounts, String detail) {
this.bookId = bookId;
this.bookName = bookName;
this.bookCounts = bookCounts;
this.detail = detail;
}

public int getBookId() { return bookId; }
public void setBookId(int bookId) { this.bookId = bookId; }
public String getBookName() {return bookName;}
public void setBookName(String bookName) {this.bookName = bookName; }
public int getBookCounts() { return bookCounts; }
public void setBookCounts(int bookCounts) { this.bookCounts = bookCounts; }
public String getDetail() { return detail; }
public void setDetail(String detail) { this.detail = detail; }

@Override
public String toString() {
return "Books{" + "bookId=" + bookId + ", bookName='" + bookName + '\'' +
", bookCounts=" + bookCounts + ", detail='" + detail + '\'' + '}';
}
}

Dao / MyBatis

数据源配置

此步骤为 MyBatis 链接数据库 并 将MyBatis与 Spring整合

数据源信息配置

database.properties

1
2
3
4
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSS=true&useUnicode=true&characterEncodeing=UTF-8&useSSL=false
jdbc.username=root
jdbc.password=123456

数据源Spring注入

spring-dao.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd">

<context:property-placeholder location="classpath:database.properties"/>
<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}"/>
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<property name="autoCommitOnClose" value="false"/>
<property name="checkoutTimeout" value="10000"/>
<property name="acquireRetryAttempts" value="2"/>
</bean>

<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>

<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.wx.dao"/>
<property name="sqlSessionFactoryBeanName" value="sessionFactory"/>
</bean>
</beans>

Dao层实现

数据库操作接口

BookMapper.java

1
2
3
4
5
6
7
8
9
10
11
12
13
package com.wx.dao;
import java.util.List;
import com.wx.pojo.Books;
import org.apache.ibatis.annotations.Param;

public interface BookMapper {
int addBook(Books books);//增加一本书
int deleteBook(@Param("bookID") int id);//删除一本书
int updateBook(Books books);//更新一本书
Books queryBookById(@Param("bookID") int id);//根据Id查询某书
List<Books> queryAllBook();//查询所有记录
Books queryBookByName(String name);//根据书名查询某书
}

MyBatis-Mapper

BookMapper.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?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="com.wx.dao.BookMapper">
<insert id="addBook" parameterType="Books">
insert into ssmbuild.books (bookName, bookCounts, detail)
VALUES (#{bookName}, #{bookCounts}, #{detail});
</insert>
<update id="updateBook">
update ssmbuild.books
set bookName = #{bookName},
bookCounts= #{bookCounts},
detail = #{detail}
where bookId = #{bookId};
</update>
<delete id="deleteBook" parameterType="int">
delete
from ssmbuild.books
where bookID = #{bookID};
</delete>
<select id="queryBookById" resultType="com.wx.pojo.Books">
select *
from ssmbuild.books
where bookID = #{bookID};
</select>
<select id="queryAllBook" resultType="com.wx.pojo.Books">
select *
from ssmbuild.books;
</select>
<select id="queryBookByName" resultType="com.wx.pojo.Books">
select *
from ssmbuild.books
where bookName = #{bookName};
</select>
</mapper>

MyBatis 配置

MyBatis的必要配置
mybatis-config.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?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>
<!--开启日志-->
<settings>
<setting name="logImpl" value="STDOUT_LOGGING"/>
</settings>
<!-- Dao包下的实体类均可以使用别名 -->
<typeAliases>
<package name="com.wx.pojo"/>
</typeAliases>
<!--注册BookMapper-->
<mappers>
<mapper class="com.wx.dao.BookMapper"/>
</mappers>
</configuration>

Service

接口

BookService.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package com.wx.service;

import java.util.List;
import com.wx.pojo.Books;

public interface BookService {

int addBook(Books books);
int deleteBook(int id);
int updateBook(Books books);
Books queryBookById(int id);
List<Books> queryAllBook();
Books queryBookByName(String name);
}

实现

BookServiceImpl.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.wx.service;
import java.util.List;
import com.wx.dao.BookMapper;
import com.wx.pojo.Books;

public class BookServiceImpl implements BookService {

private BookMapper bookMapper;
public void setBookMapper(BookMapper bookMapper) {
this.bookMapper = bookMapper;
}

public int addBook(Books books) {
return bookMapper.addBook(books);
}

public int deleteBook(int id) {
return bookMapper.deleteBook(id);
}

public int updateBook(Books books) {
return bookMapper.updateBook(books);
}

public Books queryBookById(int id) {
return bookMapper.queryBookById(id);
}

public List<Books> queryAllBook() {
return bookMapper.queryAllBook();
}

public Books queryBookByName(String name) {
return bookMapper.queryBookByName(name);
}
}

service配置

因为业务层会有异常产生,故使用aop添加事物回滚操作
spring-service.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

<context:component-scan base-package="com.wx.service"/>

<bean id="bookServiceImpl" class="com.wx.service.BookServiceImpl">
<property name="bookMapper" ref="bookMapper"/>
</bean>
<!-- 声明式事务 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- Aop事务支持 -->
<tx:advice id="interceptor" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add" propagation="REQUIRED"/>
<tx:method name="delete" propagation="REQUIRED"/>
<tx:method name="update" propagation="REQUIRED"/>
<tx:method name="query" propagation="REQUIRED"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- Aop事务切入 -->
<aop:config>
<aop:pointcut id="daoPointCut" expression="execution(* com.wx.dao.*.*(..))"/>
<aop:advisor advice-ref="interceptor" pointcut-ref="daoPointCut"/>
</aop:config>

</beans>

applicationContext.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!--引入数据源与 Service 配置-->
<import resource="classpath:spring-dao.xml"/>
<import resource="classpath:spring-service.xml"/>

<!-- 注解驱动 -->
<mvc:annotation-driven/>
<!-- 静态资源过滤 -->
<mvc:default-servlet-handler/>
<mvc:resources mapping="/" location="/statics/"/>
<!-- 扫描包 -->
<context:component-scan base-package="com.wx.controller"/>
<context:component-scan base-package="com.wx.service"/>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>

Web.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<!-- DispatcherServlet -->
<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:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--乱码过滤器-->
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 引入静态文件 -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
</web-app>

Controller

BookController.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.wx.controller;

import java.util.List;
import java.util.ArrayList;
import com.wx.pojo.Books;
import com.wx.service.BookService;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;


@Controller
@RequestMapping("/book")
public class BookController {

@Autowired
@Qualifier("bookServiceImpl")
private BookService bookService;

@RequestMapping("/allBook")
public String list(Model model) {
List<Books> books = bookService.queryAllBook();
model.addAttribute("list", books);
return "allBook";
}

@RequestMapping("/toAddBookPage")
public String toAddBookPage() {
return "addBook";
}

@RequestMapping("/addBook")
public String addBook(Books books) {
bookService.addBook(books);
return "redirect:/book/allBook";
}

@RequestMapping("/toUpdateBookPage")
public String toUpdateBookPage(int id,Model model) {
model.addAttribute("resultBooks",bookService.queryBookById(id));
return "updateBook";
}

@RequestMapping("/updateBook")
public String updateBook(Books books) {
System.out.println("============"+books);
bookService.updateBook(books);
return "redirect:/book/allBook";
}


@RequestMapping("/deleteBook")
public String deleteBook(int id) {
bookService.deleteBook(id);
return "redirect:/book/allBook";
}


@RequestMapping("/queryBook")
public String queryBook(String queryBookName,Model model) {
Books books = bookService.queryBookByName(queryBookName);
if (null == books){
return "redirect:/book/allBook";
}
List<Books> list = new ArrayList<Books>();
list.add(books);
model.addAttribute("list",list);
return "allBook";
}

}

View

index.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@ 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: bisque;
border-radius: 5px;
}
</style>
</head>
<body>
<h3>
<a href="${pageContext.request.contextPath}/book/allBook">书籍展示</a>
</h3>
</body>
</html>

allBook.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>allBook</title>
<link type="text/css" rel="stylesheet" href="/statics/css/bootstrap.css">
</head>
<body>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div class="page-header">
<h1>
<small><a href="${pageContext.request.contextPath}/index.jsp">书籍列表</a>---显示所有书籍</small>
</h1>
</div>
</div>
<div class="row clearfix">
<div class="col-md-4 column">
<a class="btn btn-primary" href="/book/toAddBookPage">新增书籍</a>
<a class="btn btn-primary" href="/book/allBook">显示书籍</a>
</div>
<div class="col-md-4 column"></div>
<div class="col-md-4 column">
<form action="${pageContext.request.contextPath}/book/queryBook" method="post" style="float:right">
<input type="text" name="queryBookName" placeholder="请输入">
<input type="submit" value="查询" class="btn btn-primary">
</form>
</div>
</div>
<div class="col-md-12 column">
<div class="page-header">
<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="${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/toUpdateBookPage?id=${book.bookId}">修改</a>|&nbsp;
<a href="${pageContext.request.contextPath}/book/deleteBook?id=${book.bookId}">删除</a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="/statics/css/bootstrap-theme.min.css"></script>
<script src="/statics/js/jquery.min.js"></script>
<script src="/statics/js/bootstrap.min.js"></script>
</body>
</html>

addBook.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>allBook</title>
<link type="text/css" rel="stylesheet" href="/statics/css/bootstrap.css">
</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="bookName">书籍名称</label>
<input type="text" class="form-control" id="bookName" name="bookName" placeholder="bookName">
</div>
<div class="form-group">
<label for="bookCounts">书籍数量</label>
<input type="text" class="form-control" id="bookCounts" name="bookCounts" placeholder="bookCounts">
</div>
<div class="form-group">
<label for="detail">书籍描述</label>
<input type="text" class="form-control" id="detail" name="detail" placeholder="detail">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
<script src="/statics/css/bootstrap-theme.min.css"></script>
<script src="/statics/js/jquery.min.js"></script>
<script src="/statics/js/bootstrap.min.js"></script>
</body>
</html>

updateBook.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>allBook</title>
<link type="text/css" rel="stylesheet" href="/statics/css/bootstrap.css">
</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">
<input type="hidden" name="bookId" value="${resultBooks.bookId}">
<div class="form-group">
<label for="bookName">书籍名称</label>
<input type="text" class="form-control" id="bookName" name="bookName" value="${resultBooks.bookName}">
</div>
<div class="form-group">
<label for="bookCounts">书籍数量</label>
<input type="text" class="form-control" id="bookCounts" name="bookCounts" value="${resultBooks.bookCounts}">
</div>
<div class="form-group">
<label for="detail">书籍描述</label>
<input type="text" class="form-control" id="detail" name="detail" value="${resultBooks.detail}">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
</div>
<script src="/statics/css/bootstrap-theme.min.css"></script>
<script src="/statics/js/jquery.min.js"></script>
<script src="/statics/js/bootstrap.min.js"></script>
</body>
</html>

配置TomCat

配置TomCat

配置TomCat,构件

配置TomCat,删除上下文

配置TomCat,链接删除上下文

war导入jar

打开项目结构

创建lib目录

lilb引入库文件

全选库文件

lilb引入库文件后的结果

运行

点击运行

运行结果


感谢查阅