thymeleaf入门简介
生活随笔
收集整理的這篇文章主要介紹了
thymeleaf入门简介
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
讀音
發(fā)音就是Time leaf
有些培訓的會念成塞姆來福
其實念啥沒問題
定義
Thymeleaf 是一個模板引擎,由于SpringBoot默認使用Thymeleaf,現(xiàn)逐步取代jsp。
特點
動靜結(jié)合:Thymeleaf 在有網(wǎng)絡和無網(wǎng)絡的環(huán)境下皆可運行,無網(wǎng)絡顯示靜態(tài)內(nèi)容,有網(wǎng)絡用后臺得到數(shù)據(jù)替換靜態(tài)內(nèi)容。支持 html 原型,瀏覽器解釋 html 時會忽略未定義的標簽屬性,所以 thymeleaf 的模板可以靜態(tài)地運行;當有數(shù)據(jù)返回到頁面時,Thymeleaf 標簽會動態(tài)地替換掉靜態(tài)內(nèi)容,使頁面動態(tài)顯示。
與SpringBoot完美整合,springboot默認整合thymeleaf。提供spring標準方言和一個與 SpringMVC 完美集成的可選模塊,可以快速的實現(xiàn)表單綁定、屬性編輯器、國際化等功能。
鏈接
官網(wǎng)
官方文檔
依賴
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>使用方式
綁定
把html等文件放在resources的templates下。
在controller文件中寫導向
傳值
@Controller //templates下的頁面需要通過controller進行跳轉(zhuǎn),使用thymeleaf public class IndexController {@GetMapping("test")public void test(Model model){model.addAttribute("msg","hello,Thymeleaf");} } <!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"xmlns:th="http://www.thymeleaf.org"> <head><meta charset="UTF-8"><title>測試</title> </head> <body><h1>test?</h1><div th:text="${msg}"></div> </body> </html> 與50位技術專家面對面20年技術見證,附贈技術全景圖總結(jié)
以上是生活随笔為你收集整理的thymeleaf入门简介的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python测试电脑性能的代码_pyth
- 下一篇: 如何绘制逻辑图 — 6.要素的属性:内聚