【发布时间】:2019-09-06 13:01:47
【问题描述】:
我有一个 SpringBoot 2.1.4.RELEASE RESTful Web Service 应用程序。使用 Spring Initializer、嵌入式 Tomcat、Thymeleaf 模板引擎,并打包为可执行 JAR 文件。
我的一个模板中有这段代码,
<tr th:each="menuPriceSummary: ${menus}" >
...
<a href="#" th:onclick="|changeAIColor('idAwesomeIconFAV${menuPriceSummary.menu.symbol}');| + 'performAjaxCall(\'' + @{/allmenupricesummary/switchfav/{id}(id=${menuPriceSummary.menu.symbol})} + '\');'" >
<span th:if="${menuPriceSummary.favorited}">
<i th:id="'idAwesomeIconFAV'+${menuPriceSummary.menu.symbol}" class="fa fa-toggle-on fa-lg" style="color:#009900; text-align: center;" aria-hidden="true"></i>
</span>
<span th:if="${!menuPriceSummary.favorited}">
<i th:id="'idAwesomeIconFAV'+${menuPriceSummary.menu.symbol}" class="fa fa-toggle-off fa-lg" style="color:#e6e6e6;" aria-hidden="true"></i>
</span>
</a>
</tr>
但是我在渲染模板时遇到了这个错误:
org.thymeleaf.exceptions.TemplateProcessingException: Only variable expressions returning numbers or booleans are allowed in this context, any other datatypes are not trusted in the context of this expression, including Strings or any other object that could be rendered as a text literal. A typical case is HTML attributes for event handlers (e.g. "onload"), in which textual data from variables should better be output to "data-*" attributes and then read from the event handler.
【问题讨论】:
-
几个月前我也有同样的问题。看看这个stackoverflow.com/questions/54224058/…
标签: html spring-boot spring-mvc thymeleaf