新建一个maven项目。直接点击next

img

输入你的项目名称

img

点击项目文件底下的pom.xml,并添加依赖

img

底下添加打包方式为war方便在Tomcat服务器下运行,如下图所示。

1
2
3
4
<groupId>com.zly</groupId>
<artifactId>SpringMVC04</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

img

添加SpringMVC的依赖,spring-webmvc和servlet-api。如下图所示。

1
2
3
4
5
6
7
8
9
10
11
12
13
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.6.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

点击导入按钮后,maven就自动引入依赖

img

在src/main下新建一个webapp文件夹

img

打开project structure 添加web.xml

img

img注意路径

img

这样设置后webapp里面就有WEB-INF文件夹和web.xml文件了

img