变量表达式 ${… …}
<input type="text" name="userName" value="James Carrot" th:value="${user.name}" />
上述代码为引用user对象的name属性值。变量表达式支持一些简单的逻辑运算以及三目运算符,如:
<span th:text="${user.popedom==0?'管理员':'普通用户'}"></span><br/>
选择/星号表达式*{* *}
<div th:object="${session.user}">
<p>Nationality: <span th:text="*{nationality}">Saturn</span>.</p> </div>
选择表达式一般跟在th:object后,直接取object中的属性
文字国际化表达式 #{… …}
<p th:utext="#{home.welcome}">Welcome to our grocery store!</p>
调用国际化的welcome语句,国际化资源文件如下
resource_en_US.properties:home.welcome=Welcome to here!
resource_zh_CN.properties:home.welcome=欢迎您的到来!
URL表达式 @{… …}
<a href="details.html" th:href="@{/order/details(orderId=${o.id})}">view</a>
@{… …}支持决定路径和相对路径。其中相对路径又支持跨上下文调用url和协议的引用
当URL为后台传出的参数时,代码如下:
<img src="../../static/assets/images/qr-code.jpg" th:src="@{${path}}" alt="二维码" />