1. 程式人生 > >Spring Boot 學習筆記(二)

Spring Boot 學習筆記(二)

imp family framework ima pri spa cal bin ges

新建Srping Boot 項目

技術分享

以下是項目結構

技術分享

由於Srping Boot內置Tomcat,所以不需要配置Tomcat就可以直接運行。

HelloWorldApplication是啟動類,我們右擊Run As 選擇 Spring Boot app。

項目運行好之後

技術分享

在瀏覽器輸入:http://localhost:8080/

技術分享

看到這個頁面項目就算啟動好了。

然後新建一個HelloWorldController類

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {
@RequestMapping("/helloWorld")
public String say() {
return "HelloWorld";
}
}

然後我們重新啟動HelloWorldApplication類

請求 http://localhost:8080/helloworld

技術分享

Spring Boot 學習筆記(二)