springBoot加入thymeleaf模板的方式
1.新建springBoot項目
在前面有兩種方式
2.加入thymeleaf模板引擎
SpringBoot推薦使用thymeleaf模板引擎語法簡單,功能更強大要想引入thymeleaf,只需要在pom,xml文件中加入如下依賴就可以了
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>
3.在controller中定義跳轉(zhuǎn)的頁面
會自動去templates文件夾下去找index.html
4.運行,然后訪問項目
輸入http://localhost:8080/testThymeleaf即可訪問index.html
5.在html頁面中加入thymeleaf模板標簽所需的命名空間
<!DOCTYPE html><html lang='en' xmlns:th='http://www.thymeleaf.org'><head> <meta charset='UTF-8'> <title>測試thymeleaf模板</title></head><body>歡迎來到測試thymeleaf界面</body></html>
6.將controller數(shù)據(jù)通過thymeleaf標簽傳到前端界面
把數(shù)據(jù)放在controller的map中
前端通過標簽取出數(shù)據(jù)
顯示效果
6.thymeleaf標簽語法
官方文檔https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.pdfthymeleaf中文https://raledong.gitbooks.io/using-thymeleaf/content/Chapter1/section1.1.html
常用標簽介紹
到此這篇關(guān)于springBoot加入thymeleaf模板的方式的文章就介紹到這了,更多相關(guān)springBoot thymeleaf模板內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Java類加載機制實現(xiàn)步驟解析2. python3實現(xiàn)往mysql中插入datetime類型的數(shù)據(jù)3. moment轉(zhuǎn)化時間戳出現(xiàn)Invalid Date的問題及解決4. python爬蟲實戰(zhàn)之制作屬于自己的一個IP代理模塊5. PHP如何打印跟蹤調(diào)試信息6. python如何實現(xiàn)word批量轉(zhuǎn)HTML7. ASP腳本組件實現(xiàn)服務(wù)器重啟8. ASP中if語句、select 、while循環(huán)的使用方法9. ASP常用日期格式化函數(shù) FormatDate()10. html小技巧之td,div標簽里內(nèi)容不換行
