2017-02-06 86 views
0

我的索引文件的正文是這樣的檢索模板:不能在我的Springboot應用

<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 
+0

您可以添加fragments/header.html文件嗎?你有任何Spring引導代碼處理這個模板? – otonglet

回答

1

有一個

< ... th:fragment="header"> 
在classpath

文件模板/片段/ header.html中?

+0

我將它添加到header.html頁面,它工作。 – santafebound

1

我不知道你能做到這一點:

<!--<div th:replace="@{'fragments/' + ${template}} :: ${template}"></div>-->

或許與前處理通過前綴和後綴加雙下劃線。

即使它被註釋掉,Thymeleaf也會處理這一行。