new Project->Maven -> 勾选Create from archetype -> 选择maven-archetype-webapp ->项目名,包名->finish
新建好的工程下面只有
项目名|_src|__main|___webapp|____WEB-INF|_____web.xml|____index.jsp|_pom.xml
我们修改目录
项目名|_src|__main|___java|___resources|___webapp|____WEB-INF|_____web.xml|____index.jsp|__test|___java|___resources|_pom.xml
我们通过File->Project Structrue->Modules快速的修改目录的属性
- main/java:Sources
- main/resources:Resources
- test/java:Tests
- test/resources: Test Resources
在java包下创建你想要取名的包名.controller
修改pom文件
<?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.chentianyu</groupId>
<artifactId>LearnSpringMvcOne_One</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- <packaging>war</packaging>打包的方式是war包-->
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!--添加springMVC的依赖-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.16</version>
</dependency>
<!--添加servlet依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
<build>
<!--指定资源文件-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/.properties</include>
</includes>
</resource>
</resources>
</build>
</project>
