SpringBoot模板引擎之Thymeleaf的使用
一. 模板引擎

1.引入thymeleaf
<properties>
<java.version>1.8</java.version>
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
<!--布局功能的支持程序 thymeleaf3主程序 layout2以上版本 -->
<!-- thymeleaf2 layout1 -->
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>只要我們把HTML頁面放在classpath:/templates/,thymeleaf就能自動(dòng)渲染;
@ConfigurationProperties(prefix = "spring.thymeleaf")
public class ThymeleafProperties {
private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8;
public static final String DEFAULT_PREFIX = "classpath:/templates/";
public static final String DEFAULT_SUFFIX = ".html";2.導(dǎo)入thymeleaf的名稱空間
<html lang="en" xmlns:th="http://www.thymeleaf.org">
3.使用thymeleaf
eg:
<div th:text="${msg}"></div>二. thymeleaf語法:
th:任意html屬性;來替換原生屬性的值

常見th標(biāo)簽:

到此這篇關(guān)于SpringBoot模板引擎之Thymeleaf的使用的文章就介紹到這了,更多相關(guān)模板引擎Thymeleaf內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java?Long類型轉(zhuǎn)為json后數(shù)據(jù)損失精度的處理方式
這篇文章主要介紹了java?Long類型轉(zhuǎn)為json后數(shù)據(jù)損失精度的處理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01
SpringBoot+Mybatis plus+React實(shí)現(xiàn)條件選擇切換搜索實(shí)踐
本文主要介紹了SpringBoot+Mybatis plus+React實(shí)現(xiàn)條件選擇切換搜索實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
springboot以FTP方式上傳文件到遠(yuǎn)程服務(wù)器
這篇文章主要介紹了springboot以FTP方式上傳文件到遠(yuǎn)程服務(wù)器,需要的朋友可以參考下2019-12-12
java.mail實(shí)現(xiàn)發(fā)送郵件
這篇文章主要為大家詳細(xì)介紹了java.mail實(shí)現(xiàn)發(fā)送郵件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02
Spring Boot Gateway 從入門到精通全面指南
Spring Cloud Gateway 作為微服務(wù)架構(gòu)中的重要組件,提供了強(qiáng)大而靈活的路由與過濾功能,通過本教程,您應(yīng)該已經(jīng)了解了如何集成 Spring Cloud Gateway、如何配置路由規(guī)則以及如何利用其豐富的功能來滿足各種業(yè)務(wù)需求,感興趣的朋友跟隨小編一起看看吧2025-09-09
Mybatis實(shí)現(xiàn)動(dòng)態(tài)排序方式
這篇文章主要介紹了Mybatis實(shí)現(xiàn)動(dòng)態(tài)排序方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10

