Hello Spring Boot
新建主函數:java -> 右鍵 -> New -> Java Class,或者快捷鍵ALT+Insert
package com.mkeeper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Chapter111Application {
public static void main(String[] args) {
SpringApplication.run(Chapter111Application.class, args);
}
}
新建HelloController,快捷鍵ALT+Insert
package com.mkeeper.controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;//@RestController 等同於 (@Controller 與 @ResponseBody)@RestControllerpublic class HelloController { //@GetMapping 等同於 (@RequestMapping(method = RequestMethod.GET)) @GetMapping("/hello") public String hello(){ return "Hello SpringBoot"; }}
啟動服務,Chapter111Application -> 右鍵 -> Run,或者快捷鍵Shift+F10
- 上圖,說明服務已啟動,端口8080
- 另外,關閉服務快捷鍵Ctrl+F2
6. 測試
打開Postman,輸入網址localhost:8080/hello
7. 結束語
開篇文章,多多包涵,有任何建議,歡迎留言探討。
閱讀更多 Mkeeper 的文章