IDEA使用Spring Initializer快速創建Spring Boot專案(超詳細)
- 創建步驟(需要聯網)
- 第一步:New - > Project
- 第二步:選擇Spring Initializer
- 第三步:撰寫相關的包名
- 第四步:選擇相應的需求模塊
- 第五步:Finish
- 沒有必要的檔案可以洗掉
- resources檔案夾中目錄結構
- 運行測驗
- 撰寫controller
- 專案目錄結構
- 啟動主程式
- 運行結果
創建步驟(需要聯網)
第一步:New - > Project

第二步:選擇Spring Initializer

第三步:撰寫相關的包名

第四步:選擇相應的需求模塊

第五步:Finish

沒有必要的檔案可以洗掉

我們可以發現:默認生成的Spring Boot專案,主程式已經生成好了,我們只需要撰寫自己的邏輯,
resources檔案夾中目錄結構
| 檔案夾 | 說明 |
|---|---|
| static | 保存所有的靜態資源如 js css images |
| templates | 保存所有的模板頁面;(Spring Boot默認jar包使用嵌入式的Tomcat,默認不支持JSP頁 面)可以使用模板引擎(freemarker、thymeleaf) |
| application.properties | Spring Boot應用的組態檔,可以修改一些默認設定 |
運行測驗
撰寫controller
HelloController:
package com.keafmd.springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* Keafmd
*
* @ClassName: HelloController
* @Description:
* @author: 牛哄哄的柯南
* @date: 2021-02-22 20:36
*/
/*@ResponseBody //這個類的所有的方法回傳的資料直接寫給瀏覽器(如果是物件還能轉為json物件)
@Controller*/
@RestController //等價于上面兩個
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "Hello World!--quick";
}
}
專案目錄結構

啟動主程式

運行結果
控制臺輸出:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.3)
2021-02-22 21:52:42.268 INFO 24532 --- [ main] s.SpringBoot01HelloworldQuickApplication : Starting SpringBoot01HelloworldQuickApplication using Java 1.8.0_181 on DESKTOP-JISCGLF with PID 24532 (F:\java_workspace\spring-boot-01-helloworld-quick\target\classes started by 章賀龍 in F:\java_workspace\spring-boot-01-helloworld-quick)
2021-02-22 21:52:42.271 INFO 24532 --- [ main] s.SpringBoot01HelloworldQuickApplication : No active profile set, falling back to default profiles: default
2021-02-22 21:52:47.963 INFO 24532 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-02-22 21:52:47.985 INFO 24532 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-02-22 21:52:47.985 INFO 24532 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-02-22 21:52:48.324 INFO 24532 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-02-22 21:52:48.324 INFO 24532 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5870 ms
2021-02-22 21:52:49.012 INFO 24532 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-02-22 21:52:50.745 INFO 24532 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-02-22 21:52:50.764 INFO 24532 --- [ main] s.SpringBoot01HelloworldQuickApplication : Started SpringBoot01HelloworldQuickApplication in 11.647 seconds (JVM running for 23.219)
訪問http://localhost:8080/hello

以上就是IDEA使用Spring Initializer快速創建Spring Boot專案(超詳細)的全部內容,
看完如果對你有幫助,感謝點贊支持!
如果你是電腦端的話,看到右下角的 “一鍵三連” 了嗎,沒錯點它[哈哈]

加油!
共同努力!
Keafmd
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/262540.html
標籤:java
上一篇:深入理解Java虛擬機(一)
