当我在括号中调用 Thymeleaf 时,它不会解析我的应用程序中的片段。这是为什么?

2023-11-29

我对春天和百里香不熟悉。 我有一个带有 thymeleaf 的 spring-boot Web 应用程序,但遇到了问题。 这条线工作完美:

<footer th:replace="fragments/footer :: footer">Footer</footer>

但是当我在它周围写上括号时,就像在文档,我收到错误。

<footer th:replace="~{fragments/footer :: footer}">Footer</footer>

Error:

出现意外错误(类型=内部服务器错误,状态=500)。 解析模板“~{fragments/footer”时出错,模板可能不存在,或者可能无法由任何配置的模板解析器访问(索引:11)

那么问题出在哪里呢,我使用默认的 spring boot 配置。 pom.xml:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.1.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

Log:

2017-03-01 22:47:51.585 ERROR 4014 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine:[THYMELEAF][http-nio-8080-exec-1]异常处理模板“index” :解析模板“~{fragments/footer”时出错,模板可能不存在,或者可能无法由任何配置的模板解析器访问(索引:11) 2017-03-01 22:47:51.591 ERROR 4014 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : servlet [dispatcherServlet] 的 Servlet.service() 在上下文中path[]抛出异常[请求处理失败;嵌套异常是 org.thymeleaf.exceptions.TemplateInputException:解析模板“~{fragments/footer”时出错,模板可能不存在或可能无法由任何配置的模板解析器 (index:11)] 访问,其根本原因 org.thymeleaf.exceptions.TemplateInputException:解析模板“~{fragments/footer”时出错,模板可能不存在或可能无法被任何配置的模板解析器访问(索引:11) 在 org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:246) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE] 在 org.thymeleaf.standard.fragment.StandardFragment.extractFragment(StandardFragment.java:202) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE] 在 org.thymeleaf.standard.processor.attr.AbstractStandardFragmentHandlingAttrProcessor.computeFragment(AbstractStandardFragmentHandlingAttrProcessor.java:72) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE] 在 org.thymeleaf.processor.attr.AbstractFragmentHandlingAttrProcessor.processAttribute(AbstractFragmentHandlingAttrProcessor.java:63) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]


看起来您正在使用 thymeleaf 2。片段表达式是 thymeleaf 3 的新功能。

http://www.thymeleaf.org/doc/articles/thymeleaf3migration.html#fragment-expressions

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当我在括号中调用 Thymeleaf 时,它不会解析我的应用程序中的片段。这是为什么? 的相关文章

随机推荐