动态百里香包括

per*_*son 3 include thymeleaf

是否可以使用这样的动态 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”

mic*_*man 5

这是可能的,但您需要稍微重建您的模板。因为th:include是在th:each你需要divth: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)