Spring+SpringMVC+MyBatis(SSM)在我们项目中是经常用到的,这篇文章主要讲解使用Intellij IDEA整合SSM,具体环境如下:
- 数据库:MySQL5.7
- 依赖管理:Maven
- IDE:Intellij IDEA
- JDK:1.8
- 服务器:Tomcat 9
首先用Intellij IDEA创建Maven项目,如果还不知道怎么创建的朋友可以先去百度谷歌,网上很多这种教程,这里我主要讲解SSM整合的过程,项目目录结构如下:
1.创建表,插入数据
CREATE TABLE user (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
name CHAR(20) NOT NULL,
password CHAR(40) NOT NULL
)
ENGINE = InnoDB
AUTO_INCREMENT = 16
DEFAULT CHARSET = utf8;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
INSERT INTO user (id,name, password) VALUES (1,'A', '123');
INSERT INTO user (id,name, password) VALUES (2,'B', '456');
- 1
- 2
2.添加Maven依赖
<?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>com.demo</groupId>
<artifactId>SSM</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>SSM</name>
<description/>
<properties>
<spring.version>4.3.4.RELEASE</spring.version>
<mybatis.version>3.4.2</mybatis.version>
<log4j.version>2.7</log4j.version>
<junit.version>4.12</junit.version>
<driver.version>5.1.40</driver.version>
</properties>
<dependencies>
<!--Spring start-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<!--绑定XML-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<!--Spring end-->
<!--AOP start-->
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.10</version>
</dependency>
<!--AOP end-->
<!--文件上传start-->
<