創建一個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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM