Expression types
Thymeleaf has five types of expressions.
type | description |
---|---|
${...} | Variable expressions. You can use any data passed as a page data model. |
*{...} | Selection expressions. Allows you to use the properties and methods of a previously selected object directly, without specifying the object itself. |
#{...} | Message (i18n) expressions. Allows to retrieve locale-specific messages from external sources (.properties files), referencing them by a key and (optionally) applying a set of parameters. |
@{...} | Link expressions. Allows to build url for attributes like href. |
~{...} | Fragment expressions. Allows to insert a markup fragment into document. As example, "top menu" can be a fragment that will be used on all pages of site. |
<span th:text="${book.author.name}"></span>
<div th:object="${book}">
...
<span th:text="*{title}"></span>
...
</div>
<table>
...
<th th:text="#{header.address.city}">...</th>
<th th:text="#{header.address.country}">...</th>
...
</table>
<!--
<a href="/myapp/order/list">...</a>
-->
<a th:href="@{/order/list}">...</a>
<!--
<a href="/myapp/order/details?id=23&type=online">...</a>
-->
<a th:href="@{/order/details(id=${orderId},type=${orderType})}">...</a>
<div th:insert="~{commons :: main}">...</div>
<!-- selects fragment as current object of div element and
replaces p element by thats fragment -->
<div th:with="frag=~{footer :: #main/text()}">
<p th:replace="${frag}">
</div>