【问题标题】:thymeleaf fragments include百里香叶片段包括
【发布时间】:2012-09-21 22:47:18
【问题描述】:

我不断收到“错误解析模板“片段/常见”,模板可能不存在或可能无法被任何已配置的模板解析器访问”。 common.html 文件路径正确,fragments->common.html。我的文件夹结构:

-- WEB-INF

---- 模板

------片段

-------- common.html

-----index.html

任何帮助或指示?

【问题讨论】:

  • 可以把你的thymeleaf bean配置一下吗?

标签: include thymeleaf


【解决方案1】:

我知道我迟到了,但我想我会分享我正在做的事情,这对我来说似乎更容易一些。

我使用 java config 类来配置 thymeleaf,并使用模板别名使其更容易:

resolver.addTemplateAlias("footerTemplate","templates/footer");

然后我可以简单地执行以下操作:

<div th:include="footerTemplate :: copy"></div>

假设您的后缀和前缀设置正确。

【讨论】:

    【解决方案2】:

    好的,我发现了问题。语法错误,错误消息说明了一切。我用的是common.html,include语句中包含的模板名不正确。

    【讨论】:

    • 你能详细说明一下吗?我在使用 thymeleaf 布局方言时遇到了同样的错误,考虑到它指向它应该在的位置,我不明白为什么会发生这种情况。
    • 包括“fragments/common.html”而不是“fragments/common”
    猜你喜欢
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    • 2015-11-29
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    相关资源
    最近更新 更多