SpringBoot基礎教程1.1.1 項目搭建

Hello Spring Boot org.springframework.boot spring-boot-starter-parent 2.0.3.RELEASE UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-maven-plugin

新建主函數:java -> 右鍵 -> New -> Java Class,或者快捷鍵ALT+Insert

SpringBoot基礎教程1.1.1 項目搭建

SpringBoot基礎教程1.1.1 項目搭建

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

SpringBoot基礎教程1.1.1 項目搭建

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

SpringBoot基礎教程1.1.1 項目搭建

  • 上圖,說明服務已啟動,端口8080
  • 另外,關閉服務快捷鍵Ctrl+F2

6. 測試

打開Postman,輸入網址localhost:8080/hello

SpringBoot基礎教程1.1.1 項目搭建

7. 結束語

開篇文章,多多包涵,有任何建議,歡迎留言探討。


SpringBoot基礎教程1.1.1 項目搭建


分享到:


相關文章: