1. 程式人生 > 其它 >建立一個springboot專案

建立一個springboot專案

1.開啟IDEA,點選 +Create New Project. 開始建立一個新專案。

  

2.在左側選單找到並點選 Spring Initializr,點選next。注意,這裡idea預設使用https://start.spring.io提供的線上模板,所以需要保證網路暢通。

當然也可以選擇下面的Custom從指定的連結載入模板。

這時,就有小朋友要問了。要是沒網不就GG了,我還是用eclipse吧。放心,IDEA不可能這麼菜。如何在本地搭建spring Initializr伺服器,

請自行百度。後面會寫一篇教程,先在這裡立個flag吧。

3.按實際情況依次填寫專案資訊。其中Type屬性可以下拉選擇project或者pom,Packaging屬性可下拉選擇jar或者war(Maven的東西不需要再提了吧)。

填寫完畢後點擊 Next。

4.最激動人心的介面來了!!!你可以從左面選擇大類,然後在視窗中間勾選需要的依賴。右邊可以看到已選擇的依賴項。

上邊下拉框可以選擇Spring Boot的版本,這裡使用最新版2.2.0 M4。完成後點選 Next。

這裡我選擇了“Web”類別下的“Spring Web Starter”、“Template”類別下的“Thymeleaf”以及“SQL”類別下的“Spring Data JPA”和“Mysql Driver”。

其餘的需要什麼就勾選什麼

5. 終於,最後一步了。設定專案名稱Project name 和 工程儲存路徑 Project location。完成後,點選 Finish。

6.等待IDEA構建好專案後,專案結構如下圖所示。根據每個人在第4步選擇的依賴不同,目錄結構大同小異。

7.再看看pom.xml,我們需要的依賴都靜靜的躺在裡面。是不是so easy,媽媽再也不用擔心我找依賴了。

8.寫個簡單頁面試試新建的工程好不好使。

spring boot,啟動。

9.訪問看看效果如何,http://localhost:8080

application.properties配置模版

# 應用名稱
spring.application.name=test
# 應用服務 WEB 訪問埠
server.port=8080
# 資料庫驅動:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 資料來源名稱
spring.datasource.name=defaultDataSource
# 資料庫連線地址
spring.datasource.url=jdbc:mysql://localhost:3306/blue?serverTimezone=UTC
# 資料庫使用者名稱&密碼:
spring.datasource.username=***
spring.datasource.password=***
# THYMELEAF (ThymeleafAutoConfiguration)
# 開啟模板快取(預設值: true )
spring.thymeleaf.cache=true
# 檢查模板是否存在,然後再呈現
spring.thymeleaf.check-template=true
# 檢查模板位置是否正確(預設值 :true )
spring.thymeleaf.check-template-location=true
#Content-Type 的值(預設值: text/html )
spring.thymeleaf.content-type=text/html
# 開啟 MVC Thymeleaf 檢視解析(預設值: true )
spring.thymeleaf.enabled=true
# 模板編碼
spring.thymeleaf.encoding=UTF-8
# 要被排除在解析之外的檢視名稱列表,⽤逗號分隔
spring.thymeleaf.excluded-view-names=
# 要運⽤於模板之上的模板模式。另⻅ StandardTemplate-ModeHandlers( 預設值: HTML5)
spring.thymeleaf.mode=HTML5
# 在構建 URL 時新增到檢視名稱前的字首(預設值: classpath:/templates/ )
spring.thymeleaf.prefix=classpath:/templates/
# 在構建 URL 時新增到檢視名稱後的字尾(預設值: .html )
spring.thymeleaf.suffix=.html
spring.http.converters.preferred-json-mapper=gson

  


參考連結:https://www.cnblogs.com/little-rain/p/11063967.html