SpringBoot模板引擎之Thymeleaf的使用
更新時間:2023年10月27日 08:49:45 作者:夜聆離殤
這篇文章主要介紹了SpringBoot模板引擎之Thymeleaf的使用,模板引擎是以業(yè)務邏輯層和表現(xiàn)層分離為目的的,將規(guī)定格式的模板代碼轉(zhuǎn)換為業(yè)務數(shù)據(jù)的算法實現(xiàn),它可以是一個過程代碼、一個類,甚至是一個類庫,需要的朋友可以參考下
一. 模板引擎

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就能自動渲染;
@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.導入thymeleaf的名稱空間
<html lang="en" xmlns:th="http://www.thymeleaf.org">
3.使用thymeleaf
eg:
<div th:text="${msg}"></div>二. thymeleaf語法:
th:任意html屬性;來替換原生屬性的值

常見th標簽:

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

