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

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內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
解決idea中Terminal終端無法執(zhí)行GIT命令+Terminal 中文亂碼問題
這篇文章主要介紹了解決idea中Terminal終端無法執(zhí)行GIT命令+Terminal 中文亂碼問題,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07
Springboot項目Mybatis升級為Mybatis-Plus的詳細步驟
在許多 Java 項目中,MyBatis 是一個廣泛使用的 ORM 框架,然而,隨著 MyBatis-Plus 的出現,許多開發(fā)者開始遷移到這個更加簡潔、高效的工具,它在 MyBatis 的基礎上提供了更多的功能,所以本文將介紹Springboot項目Mybatis升級為Mybatis-Plus的詳細步驟2025-03-03

