spring mvc 書籍Spring in Action, 4th Edition
java項目建立流程
1 使用maven來管理項目中的庫。
先用marven建立一個框架
mvn archetype:generate -DgroupId=com.webtest -DartifactId=WebTest -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
把該項目變成IDEA支持的項目
mvn idea:idea
2 導入intelIJ IDE中,導入時選擇pom.xml
3 根據需更改pom.xml添加jar庫
<?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>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
4 在源碼目錄建立源文件,使用spring MVC框架與spring boot
目錄結構
├─src
│ └─main
│ ├─java
│ │ └─com
│ │ └─webtest
│ │ ├─config
│ │ └─web
│ ├─resources
│ └─webapp
│ └─WEB-INF
│ └─views
config目錄用來存儲配置代碼
web目錄存儲控制器代碼
views目錄存放jsp代碼
5在intelljIDE調試完成后使用mvn打war包
mvn clean install
源碼:git@github.com:mingzhangchn/WebTest.git