【发布时间】:2017-02-22 05:43:23
【问题描述】:
如果${object} 为空,那么*{item} 访问的项目将导致:
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'item' cannot be found on null
那么如何解决这个问题,我希望保留 div 结构,如下例所示,当currentUser 为空时,div 包含城市和名称仍然存在。
<div class="form" th:object="${currentUser}">
<div class="form-group form-group-sm">
<label>city:</label>
<span id="details_city" th:text="*{address == null ? '' : address.city}">Hongkong</span>
</div>
<div class="form-group form-group-sm">
<label>name:</label>
<span id="details_username" th:text="*{name}">Jane</span>
</div>
</div>
【问题讨论】:
标签: thymeleaf