一,创建项目
1.创建mavenweb项目
2.清理pom.xml文件
<?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>UserTest</groupId>
<artifactId>usertest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
</project>
3.补全缺失目录
4.为目录创建正确的类型:Ctrl + Alt + Shift + s 快捷键设置补全目录的类型
二,引入依赖
1.dao层依赖
<!--引入MySQL依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<!--引入mybatis依赖-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.2</version>
</dependency>
<!--引入mybatis-spring依赖-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.2</version>
</dependency>
<!--引入spring-jdbc依赖-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
<!--druid为阿里巴巴的数据源,(数据库连接池),
集合了c3p0、dbcp、proxool等连接池的优点,
还加入了日志监控,有效的监控DB池连接和SQL的执行情况。-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.20</version>
</dependency>
2.controller层依赖
<!--spring-web的等级大于Spring-webmvc-->
<!--但是在maven中配置了Spring-webmvc的依赖后
,是包含Spring-web的依赖的-->
<!--所以使用时,如果不太了解,建议导Spring-webmvc的依赖
,因为已经包含了Spring-web了-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
<!--使用jsp的话-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!--上传文件的话spring MVC上传文件-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>