【问题标题】:Dynamic Thymeleaf include动态百里香包括
【发布时间】: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”

【问题讨论】:

    标签: include thymeleaf


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-09-21
      • 1970-01-01
      • 1970-01-01
      • 2020-12-30
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 2021-01-09
      • 2018-02-03
      相关资源
      最近更新 更多