Spring boot 2.0.4
Thymeleaf 3.0.9
JDK8
@{} 鏈接地址處理
<a th:href="@{'/thymeleaf'}" >
跳轉到thymeleaf
</a>
th:href 屬性中用 @ 前綴輸出地址,自動補全ContentPath
某些情況下,項目部署直接部署在 / 根目錄下的,如 http://www.abc.com/app/
在模板中使用@{} 自動轉換爲 href=”/app/thymeleaf”
@前綴 Spring IOC 中Bean的引用
<a th:text="${@abean.size()}" href="#">
名稱爲 abean 的 size 方法返回值
</a>
#前綴 特殊對象
${#conversions.convert(val,'String')} 轉換服務,調用SpringConversionService
${#fields} org.thymeleaf.spring5.expression.Fields
${#this} 和 ${#root} 代表了表達式上下文的對象,#root就是當前的表達式上下文對象,#this則根據當前求值環境的不同而變化。
${#httpServletRequest}
#{} 多國語言支持/國際化
<a th:text="#{myhref.text}" href="#">
My
</a>
默認的
# Messages.properties
myhref.text=My
中文的
# Messages-zh.properties
myhref.text=我的
Messages.properties 在 classpath:/ 目錄中
[[ ]] 模板頁中內嵌的javascript中輸出
script 標籤需加上 th:inline=”javascript” 才能生效
<script type="text/javascript" th:inline="javascript">
var href = [[@{/thymeleaf}]];
var val = [[${}]];
</script>