具有嵌套(递归)评估和 th:replace 的 Thymeleaf

Thymeleaf with nested (recursive) evaluation and th:replace

我正在尝试创建一个模板,允许我将一个属性传递给模型,指定将用于替换模板中的 div 标签的片段的名称。

模板代码为:

    <div th:replace="${__${T(mypackage.WebUtils).INCLUDE_FRAGMENT_NAME}__}"/>

(INCLUDE_FRAGMENT_NAME的值为"fragment"。 在我的控制器中我有:

model.addAttribute(WebUtils.INCLUDE_FRAGMENT_NAME, WebUtils.MAIN_OVERVIEW_DIV_INCLUDE);

其中 MAIN_OVERVIEW_DIV_INCLUDE 为 "main/main :: fragment"。

我得到的错误是这个:

HTTP Status 500 - Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "ServletContext resource [/WEB-INF/templates/main/main :: fragment.html]" - line 43, col 14)

我知道 URL 是错误的,但我不知道如何解决这个问题。有帮助吗?

此外,如果我可以在 main/main 中动态设置片段名称就好了,但我想这是不可能的,因为片段在被包含之前没有被评估,对吧?

谢谢!

问题与 https://github.com/thymeleaf/thymeleaf-spring/issues/77 有关 - 将代码更改为

<div th:replace="${__${T(mypackage.WebUtils).INCLUDE_FILE_VAR_NAME}__} :: ${__${T(mypackage.WebUtils).INCLUDE_FRAGMENT_VAR_NAME}__}"/>

为我解决了问题。动态片段名称见http://forum.thymeleaf.org/Thymeleaf-3-with-nested-recursive-evaluation-and-th-replace-td4029392.html#a4029395