是否可以使用这样的动态 Thymeleaf 包含:
<div th:each="module : ${report.modules}" th:include="modules/${module.key} :: ${module.key}"></div>
Run Code Online (Sandbox Code Playgroud)
加载页面时我得到 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>
Run Code Online (Sandbox Code Playgroud)