[英]Cannot retrieve template in my Springboot application
我的索引文件的正文如下所示:
<div class="container" style="width: 100% !important;">
<!--Header-->
<div th:replace="fragments/header :: header"></div>
<!--Content-->
<!--<div th:replace="@{'fragments/' + ${template}} :: ${template}"></div>-->
<!--Footer-->
<div th:replace="fragments/footer :: footer"></div>
</div>
它似乎在抱怨我的標題評論下的行,但我不確定為什么。 會發生什么?
這是我的錯誤:
Mon Feb 06 16:06:26 CET 2017
There was an unexpected error (type=Internal Server Error, status=500).
Error resolving fragment: "~{'fragments/header' :: header}": template or fragment could not be resolved (template: "index" - line 34, col 10)
例外:
org.thymeleaf.exceptions.TemplateInputException: Error resolving fragment: "~{'fragments/header' :: header}": template or fragment could not be resolved (template: "index" - line 34, col 10)
at org.thymeleaf.standard.expression.FragmentExpression.resolveExecutedFragmentExpression(FragmentExpression.java:593) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.standard.processor.AbstractStandardFragmentInsertionTagProcessor.computeFragment(AbstractStandardFragmentInsertionTagProcessor.java:368) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.standard.processor.AbstractStandardFragmentInsertionTagProcessor.doProcess(AbstractStandardFragmentInsertionTagProcessor.java:111) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.engine.ProcessorTemplateHandler.handleOpenElement(ProcessorTemplateHandler.java:1314) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.engine.OpenElementTag.beHandled(OpenElementTag.java:205) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.engine.TemplateModel.process(TemplateModel.java:136) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:593) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) ~[thymeleaf-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:337) ~[thymeleaf-spring5-3.0.3.M1.jar:3.0.3.M1]
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:186) ~[thymeleaf-spring5-3.0.3.M1.jar:3.0.3.M1]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1271) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:964) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:856) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:841) ~[spring-webmvc-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.11.jar:8.5.11]
at
是否有一個文件 templates/fragments/header.html
< ... th:fragment="header">
在類路徑中?
我不確定你能不能做到:
<!--<div th:replace="@{'fragments/' + ${template}} :: ${template}"></div>-->
或者可能通過前綴和后綴雙下划線進行預處理。
即使已注釋掉,Thymeleaf 也會處理此行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.