springBoot加入thymeleaf模板的方式
1.新建springBoot項(xiàng)目
在前面有兩種方式
2.加入thymeleaf模板引擎
SpringBoot推薦使用thymeleaf模板引擎
語(yǔ)法簡(jiǎn)單,功能更強(qiáng)大
要想引入thymeleaf,只需要在pom,xml文件中加入如下依賴(lài)就可以了

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
3.在controller中定義跳轉(zhuǎn)的頁(yè)面

會(huì)自動(dòng)去templates文件夾下去找index.html

4.運(yùn)行,然后訪問(wèn)項(xiàng)目
輸入http://localhost:8080/testThymeleaf即可訪問(wèn)index.html

5.在html頁(yè)面中加入thymeleaf模板標(biāo)簽所需的命名空間

<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>測(cè)試thymeleaf模板</title> </head> <body> 歡迎來(lái)到測(cè)試thymeleaf界面 </body> </html>
6.將controller數(shù)據(jù)通過(guò)thymeleaf標(biāo)簽傳到前端界面
把數(shù)據(jù)放在controller的map中

前端通過(guò)標(biāo)簽取出數(shù)據(jù)

顯示效果

6.thymeleaf標(biāo)簽語(yǔ)法
官方文檔
https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.pdf
thymeleaf中文
https://raledong.gitbooks.io/using-thymeleaf/content/Chapter1/section1.1.html
常用標(biāo)簽介紹



到此這篇關(guān)于springBoot加入thymeleaf模板的方式的文章就介紹到這了,更多相關(guān)springBoot thymeleaf模板內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
ActiveMQ中consumer的消息確認(rèn)機(jī)制詳解
這篇文章主要介紹了ActiveMQ中consumer的消息確認(rèn)機(jī)制詳解,對(duì)于broker而言,只有接收到確認(rèn)指令,才會(huì)認(rèn)為消息被正確的接收或者處理成功了,InforSuiteMQ提供以下幾種Consumer與Broker之間的消息確認(rèn)方式,需要的朋友可以參考下2023-10-10
使用spring mail發(fā)送html郵件的示例代碼
本篇文章主要介紹了使用spring mail發(fā)送html郵件的示例代碼,這里整理了詳細(xì)的示例代碼,具有一定的參考價(jià)值,有興趣的可以了解一下2017-09-09
JAVA如何使用Math類(lèi)操作數(shù)據(jù)
這篇文章主要介紹了JAVA如何使用Math類(lèi)操作數(shù)據(jù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04
Spring Boot結(jié)合ECharts案例演示示例
本文主要主要介紹了Spring Boot結(jié)合ECharts案例演示示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06

