概述
Thymeleaf的用${...
}来表示变量表达式,正常情况下,执行${...}
时,实际上是针对context中的variables map执行OGNL表达式。在与SpringMVC集成的时候,用的是Spring EL。
<p>Today is: <span th:text="${today}">13 february 2011</span>.</p>
实际等效于执行了
ctx.getVariables().get("today");
<p th:utext="#{home.welcome(${session.user.name})}">
Welcome to our grocery store, Sebastian Pepper!
</p>
等效于执行了
((User) ctx.getVariables().get("session").get("user")).getName();
因为底层实际上是执行的OGNL解析,所以${...}
支持许多语法
/*
* Access to properties using the point (.). Equivalent to calling property getters.
*/
${person.father.name}
/*
* Access to properties can also be made by using brackets ([]) and writing
* the name of the property as a variable or between single quotes.
*/
${person['father']['name']}
/*
* If the object is a map, both dot and bracket syntax will be equivalent to
* executing a call on its get(...) method.
*/
${countriesByCode.ES}
${personsByName['Stephen Zucchini'].age}
/*
* Indexed access to arrays or collections is also performed with brackets,
* writing the index without quotes.
*/
${personsArray[0].name}
/*
* Methods can be called, even with arguments.
*/
${person.createCompleteName()}
${person.createCompleteNameWithSeparator('-')}
最后
以上就是简单抽屉为你收集整理的Thymeleaf变量表达式的全部内容,希望文章能够帮你解决Thymeleaf变量表达式所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复