【发布时间】:2017-01-22 13:00:04
【问题描述】:
我正在尝试使用 Spring Boot 中的一些数据填充 thymeleaf 模板。 我想做的是这个
<tr th:if="${group.organization}">
<td class="col_title"><b>Organization:</b></td>
<td class="organization-field-content" th:text="${group.organization}"></td>
</tr>
我已经尝试了这里提出的两种解决方案:
Thymeleaf: show text if the attribute and property exists
并且按照 thymeleaf 的渲染顺序,由于group.organization 为空,所以不应显示整个内部的tds。
仍然存在问题,因为 Thymeleaf 抱怨说
Servlet.service() for servlet [dispatcherServlet] in context with path []
threw exception [Request processing failed; nested exception is
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating
SpringEL expression: "group.organization" (group)] with root cause
java.lang.NullPointerException: null
我不明白为什么会这样,因为组对象存在,只是组织为空
【问题讨论】:
-
organization是boolean属性吗?如果没有,这样做更有意义:<tr th:if="${group != null && group.organization != null}"> <td class="col_title"><b>Organization:</b></td> <td class="organization-field-content" th:text="${group.organization}"></td> </tr>
标签: java spring-boot thymeleaf