【发布时间】:2014-02-27 00:59:01
【问题描述】:
如果属性和属性存在,thymeleaf 中是否有一种简单的方法来显示属性属性的内容?如果我的 html 页面中有属性“错误”和属性“摘要”,我想显示它:
<span th:text="${error.summary}">error summary</span>
如果没有属性“错误”,则会引发以下错误:
org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'summary' cannot be found on null
目前我正在使用以下方法,这似乎太复杂了。
<span th:if="${error != null and error.summary != null}"><span th:text="${error.summary}">error summary</span></span>
有没有更简单的方法来实现这一点?
【问题讨论】:
标签: spring thymeleaf spring-el