一、引用命名空間
在html中引入此命名空間,可避免編輯器出現html驗證錯誤,雖然加不加命名空間對thymeleaf的功能沒有任何影響。
二、輸出內容
2.1 welcome to our grocery store!
說明:1. th:text 用來將內容輸出到所在標籤的body中。
2. # 用來引入資料home物件中的 welcome屬性。
3. 可以用th:utext 用來顯示「unescaped 」 的html內容。
2.2 today is: 13 february 2011
說明:$ 用來引用 today 變數
三、訪問物件
$ 返回名為x 的 request引數。(可能有多個值)
$ 返回名為x的session引數。
四、基本語法
4.1 #{home.welcome} -- 訪問資料
4.2 #)} -- 格式化資料 當 home.welcome 為 "abcdegf" 類似這種內容時。(多個引數以逗句分隔)。
4.3 $ --- 訪問變數
4.4 訪問基本物件
4.5 日期的輸出
13 may 2011
4.6 星號語法
name: sebastian.
surname: pepper.
nationality: saturn.
4.7 輸出url
product list
view
4.8 使用**段
...
4.9 直接輸出內容
-- 輸出資料表示式
--輸出布林表示式
4.10 條件表示式
...
...省略 false 結果的表達方式
...省略 true 結果的表達方式
age: 27.
no user authenticated --不做任何處理時用下劃線 _ 表示
4.11 格式化
... --$} 呼叫預設的格式化器來輸出結果。
4.12 預處理
some text here...
說明:thymeleaf 的處理模板內容的順序與書寫順序無關,只能通過 __$__ ,來將需要先一步計算出來後面 要用的變數指定為優化處理。
五、設定 attribute 值
5.1 設定任何attribute 的方法
--設定單個
5.2 設定一些內建的attribute的方法
product list
其它的可用屬性:
5.3 設定html裡沒有指的任何屬性的語法
... ---whatever 可以換成任何你想設的屬性
六、迴圈輸出的語法
6.1 基本迴圈
onions
2.41
yes
6.2 迴圈狀態的使用
name
price
in stock
onions
2.41
yes
關於狀態的其它資訊的使用詳細參考:
七、條件判斷
7.1 if 和 unless
view
view
7.2 switch 語句
user is an administrator
user is a manager
user is some other thing
--預設的 case 相當於default
八、模板 include
8.1 定義和引用**塊
定義**塊
引用**塊
引用未用fragment 標註的**塊
8.2 th:insert th:replace th:include 之間的區別
th:insert --- 插入**塊 th:replace -- 替換**塊會替換掉容器標籤 th:include ---- 和insert相似但只會插入fragment標註body內的內容。
8.3 帶引數的**段
...
......
九、區域性變數的使用示例
the name of the first person is julius caesar.
the name of the first person is julius caesar.
but the name of the second person is
marcus antonius.
十、注釋
十
一、說明
以上只列出thymeleaf了簡要常用的語法和使用方式,更多詳情的說明和規則請參見:
Thymeleaf 基本用法總結
thymeleaf 基本用法總結 一 引用命名空間 在html中引入此命名空間,可避免編輯器出現html驗證錯誤,雖然加不加命名空間對thymeleaf的功能沒有任何影響。二 輸出內容 2.1 welcome to our grocery store 說明 1.th text 用來將內容輸出到所在標...
Thymeleaf 基本用法總結
一 引用命名空間 在html中引入此命名空間,可避免編輯器出現html驗證錯誤,雖然加不加命名空間對thymeleaf的功能沒有任何影響。二 輸出內容 2.1 welcome to our grocery store 說明 1.th text 用來將內容輸出到所在標籤的body中。2.用來引入資料h...
Thymeleaf 基本用法總結
一 引用命名空間 在html中引入此命名空間,可避免編輯器出現html驗證錯誤,雖然加不加命名空間對thymeleaf的功能沒有任何影響。二 輸出內容 2.1 welcome to our grocery store 說明 1.th text 用來將內容輸出到所在標籤的body中。2.用來引入資料h...