【发布时间】:2014-05-01 19:10:56
【问题描述】:
是否可以像这样使用动态 Thymeleaf 包含:
<div th:each="module : ${report.modules}" th:include="modules/${module.key} :: ${module.key}"></div>
加载页面时我得到 500: 评估 SpringEL 表达式的异常:“module.key”
【问题讨论】:
是否可以像这样使用动态 Thymeleaf 包含:
<div th:each="module : ${report.modules}" th:include="modules/${module.key} :: ${module.key}"></div>
加载页面时我得到 500: 评估 SpringEL 表达式的异常:“module.key”
【问题讨论】:
这是可能的,但您需要稍微重建您的模板。因为th:include 在th:each 之前处理,您需要将div 与th:include 包装到迭代标记。模板的路径也必须是String,所以你不能做modules/$module.key,因为我想它不会产生预期的结果。请参见下面的示例。
<th:block th:each="module : ${report.modules}">
<div th:include="${#strings.concat('modules/', module.key)} :: ${module.key}"></div>
</th:block>
【讨论】: