Spring Boot + MyBatis 電商專案 - 02- 引入 Spring Boot 依賴包
阿新 • • 發佈:2019-01-06
Spring Boot + MyBatis 電商專案 - 02- 引入 Spring Boot 依賴包
上一篇 Spring Boot + MyBatis 電商專案 - 01- 開題 + 建立專案 我們已經建立好了 quickstart 專案
一、載入 Spring Boot 依賴包,配置 pom.xml 檔案:
方法一:
百度:maven Spring Boot ,點第一個:
點進去都點第一個最新版就可以:
(1)Spring Boot Test Starter:
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.1.RELEASE</version>
<scope>test</scope>
</dependency>
(2)Spring Boot Web Starter:
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
(3)拷貝到專案的 pom.xml 檔案中,注意位置:
方法二
(1)開啟官方文件:
(2)展開 Build with Maven,有配置檔案:
二、不管哪個方法,再引入一個:
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
三、指定 parent ,注意位置:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
位置:
四、簡單編寫 App.java 檔案:
package com.miaoshapro;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Hello world!
*
*/
//自動配置註解,自動掃描,載入到專案工程中
@EnableAutoConfiguration
//
@RestController
public class App {
//請求對映,當請求 /home 時執行該方法
@RequestMapping("/home")
public String home(){
return "Hello home!";
}
public static void main( String[] args ) {
System.out.println( "Hello World!" );
//啟動 Web 容器
SpringApplication.run(App.class, args);
}
}
五、執行伺服器
控制檯會列印:
六、開啟瀏覽器訪問:
http://localhost:8080/home
home 是剛才設定的對映路徑