1.訪問如下地址來構建基礎項目
地址:http://start.spring.io/
2.具體操作選項如下
a.Generate a:創建一個什麼樣的工程,這裏選擇Maven Project
b.with:通過什麼語言,這裏選擇Java
c.and Spring Boot:這個是選擇spring boot的版本,這裏選擇2.1.1
d.Project Metadata:項目元數據信息查看截圖
3.點擊Generate Project下載項目壓縮包
4.解壓下載的壓縮包
5.通過IDE導入項目,這裏使用IntelliJ IDEA,導入步驟查看截圖
6.項目結構說明截圖如下
a.src/main/java:程序開發的原碼文件以及主程序入口
b.src/main/resources:存儲配置及資源文件
c.src/test/java:程序開發的相關測試代碼
d.pom.xml:是我們程序的相關依賴,依賴截圖查看以下截圖
7.創建HelloWorld示例
a.創建包,在父包com.huinongtx.demospringboot上右鍵選擇New->Package
包名:web
b.創建類,在web包上右鍵選擇New->Java Class
類名:HelloWorldControl
類的內容:
package com.huinongtx.demospringboot.web;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by dengdashuai on 2018/12/6.
*/
@RestController
public class HelloWorldControl {
@RequestMapping("/helloworld")
public String index() {
return "Hello World";
}
}
8.在DemospringbootApplication中右鍵運行項目,在瀏覽瀏覽器中訪問http://localhost:8080/helloworld可以查看結果,當看到輸出"Hello World"表示整個項目已配置構建完成。