我試圖用Spring Boot中的一些數據填充thymeleaf模板。 我想要做的就是這個Thymeleaf th:如果出現空錯誤
<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
爲空,整個內td
小號不應顯示。
仍然存在一個問題,因爲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
我不明白爲什麼會這樣,因爲組對象存在,只是該組織爲null
是'組織''布爾'屬性?如果不是這樣,則更有意義: '