用到的环境:
CREATE DATABASE IF NOT EXISTS `ssmbuild`;
use `ssmbuild`;
CREATE TABLE IF NOT EXISTS `books`(
`bookID` INT(10) NOT NULL AUTO_INCREMENT COMMENT '书ID',
`bookName` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '书名',
`bookCounts` INT(50) NOT NULL DEFAULT 0 COMMENT '书的数量',
`detail` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '描述',
PRIMARY KEY(`bookID`)
)ENGINE=INNODB DEFAULT charset=utf8mb4;
INSERT INTO `books`(`bookID`, `bookName`, `bookCounts`, `detail`) VALUES
(1, '高等数学', 2, '第一排第一个'),
(2, '计算机网络', 5, '第二排第二个'),
(3, '通信原理', 3, '第一排第三个');
<dependencies>
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- mysql 数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
<!-- 数据库连接池 c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.5</version>
</dependency>
<!-- Servlet 依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- JSP 依赖 -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<!-- JSTL 表达式依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- MyBatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.7</version>
</dependency>
<!-- mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.6</version>
</dependency>
<!-- spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.18</version>
</dependency>
<!-- aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.6</version>
</dependency>
<!-- spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.23</version>
</dependency>
<!-- jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.1</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
</dependencies>
<!-- 在 build 中配置 resources,来防止我们静态资源导出失败的问题 -->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
外部配置文件
MyBatis 核心配置文件
实体类
接口
实现类
业务接口:业务一般是和数据库对应的
业务实现类:service 层调 dao 层
Spring 整合 dao 层配置文件:spring-dao.xml
Spring 整合 service 层配置文件:spring-service.xml
把普通 Maven 项目转为 Web 项目,打开项目结构,添加 lib 目录,添加依赖
配置 web.xml
Spring 整合 controller 层配置文件:spring-mvc.xml
整合 Spring 配置文件,得到 Spring 的最终配置文件:applicationContext.xml
编写控制类
编写页面
配置 Tomcat,发布项目,运行