學(xué)習(xí)完整課程請移步 互聯(lián)網(wǎng) Java 全棧工程師
Message 表達(dá)式
#{...}
<p th:utext="#{home.welcome(${session.user.name})}"> Welcome to our grocery store, Sebastian Pepper!</p>
<p th:utext="#{${welcomeMsgKey}(${session.user.name})}"> Welcome to our grocery store, Sebastian Pepper!</p>
變量表達(dá)式
${}
ongl 標(biāo)準(zhǔn)語法,方法也可以被調(diào)用
選擇變量表達(dá)式
*{}
<div th:object="${session.user}">
<p>Name: <span th:text="*{firstName}">Sebastian</span>.</p>
<p>Surname: <span th:text="*{lastName}">Pepper</span>.</p>
<p>Nationality: <span th:text={nationality}">Saturn</span>.</p>
</div>
等價(jià)于
<div>
<p>Name: <span th:text="${session.user.firstName}">Sebastian</span>.</p>
<p>Surname: <span th:text="${session.user.lastName}">Pepper</span>.</p>
<p>Nationality: <span th:text="${session.user.nationality}">Saturn</span>.</p>
</div>
當(dāng)然了,這兩者可以混合使用
還有一種方式
<div>
<p>Name: <span th:text="*{session.user.name}">Sebastian</span>.</p>
<p>Surname: <span th:text="*{session.user.surname}">Pepper</span>.</p>
<p>Nationality: <span th:text="*{session.user.nationality}">Saturn</span>.</p>
</div>
鏈接 URL 表達(dá)式
@{}
<!-- Will produce 'http://localhost:8080/gtvg/order/details?orderId=3' (plus rewriting) --> <a href="details.html"
th:href="@{http://localhost:8080/gtvg/order/details(orderId=${o.id})}">view</a> <!-- Will produce '/gtvg/order/details?orderId=3' (plus rewriting) -->
<a href="details.html" th:href="@{/order/details(orderId=${o.id})}">view</a>
<!-- Will produce '/gtvg/order/3/details' (plus rewriting) -->
<a href="details.html" th:href="@{/order/{orderId}/details(orderId=${o.id})}">view</a>
變量
| 分類 | 實(shí)例 |
|---|---|
| 文本 |
one text,Another one!,... |
| 數(shù)字 | 0 , 34 , 3.0 , 12.3 ,… |
| 真假 | true , false |
| 文字符號 | one , sometext , main ,… |
算數(shù)運(yùn)算
| 分類 | 實(shí)例 |
|---|---|
| +, -, *, /, % | 二元運(yùn)算符 |
| - | 減號(一元運(yùn)算符) |
真假運(yùn)算
| 分類 | 實(shí)例 |
|---|---|
| and , or | 二元運(yùn)算符 |
| ! , not | 否定(一元運(yùn)算符) |
比較運(yùn)算
| 分類 | 實(shí)例 |
|---|---|
| >, <, >=, <= (gt, lt, ge, le) | 比較 |
| == , != ( eq , ne ) | 平等 |
條件運(yùn)算
| 分類 | 實(shí)例 |
|---|---|
| if-then | (if) ? (then) |
| if-then-else | (if) ? (then) : (else) |
| Default | (value) ?: (defaultvalue) |