一:準備環境
1.JDK環境:JDK1.8
開發環境:IDEA2018.3
二:創建IDEA項目工程
三:HelloWorld實例
-
目錄結構:
-
編寫controllor代碼
package com.controller; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @EnableAutoConfiguration public class helloController { @RequestMapping("/hello") private String hello(){ return "Hello World!"; } }
-
注意!!!
DemoApplication 一定要放在包的最外層!!!否則出現以下錯誤!!!
四:項目啓動
兩種方式:
- application啓動
-
IDEA工具欄啓動
五:測試helloworld
打開瀏覽器輸入: http://localhost:8080/hello