1.建立一個Spring Starter Project工程(new --> Spring Starter Project)java
2.選擇本身須要的依賴,由於想要經過REST方式來驗證是否成功建立,因此勾選了web(會在pom.xml文件中看到該依賴內容);而後點擊next-->Finish便可git
3.此時就能夠建立完了,下面是程序入口github
package com.fengxm; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class FirstspringbootApplication { public static void main(String[] args) { SpringApplication.run(FirstspringbootApplication.class, args); } }
4.寫一個HelloController類,用於圖形驗證web
package com.fengxm; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController // 等同於同時加上了@Controller和@ResponseBody public class HelloController { // 訪問/hello或者/hi任何一個地址,都會返回同樣的結果 @RequestMapping(value = { "/hello", "/hi" }, method = RequestMethod.GET) public String say() { return "hi you!!!"; } }
5.在FirstspringbootApplication.java類上右鍵,Run As -->Spring Boot App,執行(默認端口爲8080)spring
在瀏覽器中輸入鏈接http://localhost:8080/hello或http://localhost:8080/hi,在頁面顯示以下瀏覽器
代碼地址springboot
參考:方誌鵬的博客app