初識SpringBoot之快速入門
阿新 • • 發佈:2020-12-12
技術標籤:spring bootjavamaven
SpringBoot框架能夠讓我們快速的使用Spring框架。
Spring框架在使用的開始需要在pom檔案中匯入大量座標(依賴)。SpringBoot的開發人員基於“約定優於配置”的思想,把我們所依賴的資源封裝起來,使用預設的依賴資源,當然也可以自己配置。
SpringBoot快速入門
首先建立一個maven模組,我們需要現在pom.xml檔案中配置SpringBoot工程所需要繼承的父工程。
<!-- springBoot工程所需要繼承的父工程-->
<parent>
< groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
</parent>
匯入SpringBoot需要的起步依賴
<!-- springBoot web開發的起步依賴-->
<dependencies>
<dependency >
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
注意第一次使用,需要聯網下載資源。
簡單使用
建立HelloController類
@RestController
public class HelloController {
@RequestMapping ("/hello")
public String hello(){
return "holle Spring Boot!!";
}
}
重點是我們還要寫一個引導類HelloApplication
/**
* 引導類 SpringBoot的專案入口
*/
@SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
因為SpringBoot內建的有tomcat,所以我們直接執行。
在瀏覽器輸入http://localhost:8080/hello回車。就會輸出holle Spring Boot!!
idea那邊也會顯示各種資訊。