<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent> <!--Spring Boot的版本仲裁中心;以後我們導入依賴默認是不需要寫版本。(沒有在dependencies裏面管理的依賴自然需要聲明版本號)-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
spring-boot-starter-web:
spring-boot-starter:spring-boot場景啓動器。幫我們導入了web模塊正常運行所依賴的組件。
Spring Boot將所有的功能場景都抽取出來,做成一個個的starters(啓動器),只需要在項目裏面引入這些starter 相關場景的所有依賴都會導入進來。要用什麼功能就導入什麼場景的啓動器
包結構:
HelloController.java
@RestController//標註是一個Controller類 並且支持json數據格式輸出
public class HelloController { //通過 http://localhost:8080/sayHello訪問該方法
@RequestMapping("/sayHello")
public String hello(){
return "hello world";
}
}
MainTest.java
@SpringBootApplication//代表springboot的啓動類 用來標註主程序類 說明是一個springboot應用
public class MainTest {
public static void main(String[] args) { //將springboot應用驅動起來
SpringApplication.run(MainTest.class);
}
}