Java org.thymeleaf.exceptions.TemplateInputException:解析片段时出错:无法解析模板或片段

Java org.thymeleaf.exceptions.TemplateInputException:解析片段时出错:无法解析模板或片段,java,spring-boot,thymeleaf,Java,Spring Boot,Thymeleaf,我有一个奇怪的问题,当我使用replace或include时,我的一些html文件没有被包括在内。这是什么原因造成的 header.html <header id="header" xmlns:th="http://www.thymeleaf.org"> <div th:replace="/blocks/topbar :: topbar"></div> </header> 您的topbar.html中没有th:fragment=

我有一个奇怪的问题,当我使用replace或include时,我的一些html文件没有被包括在内。这是什么原因造成的

header.html

 <header id="header" xmlns:th="http://www.thymeleaf.org">
       <div th:replace="/blocks/topbar :: topbar"></div>
 </header>

您的
topbar.html
中没有
th:fragment=“topbar”
。 额外的
可能会解决您的问题


+01234567090


您并不总是需要th:fragment,您可以使用“.top bar”而不是“topbar”:



类选择器是完全有效的,您在thymeleaf中有更多的选择器可能性,请参见此处:

这解决了我的问题,但为什么其他包含没有片段表达式,而其他包含没有片段表达式?我不能确切地说,因为我无法使它在没有表达式的情况下工作。
<div class="top-bar">
    <div class="container">
        <div class="row">
            <div class="col-sm-6 col-xs-4">
                <div class="top-number"><p><i class="fa fa-phone-square"></i>  +0123 456 70 90</p></div>
           </div>
         <div class="col-sm-6 col-xs-8">
            <div class="social">
                <ul class="social-share">
                    <li><a href="#"><i class="fa fa-facebook"></i></a></li>
                </ul>
            </div>
        </div>
      </div>
    </div><!--/.container-->
</div><!--/.top-bar-->
 org.thymeleaf.exceptions.TemplateInputException: Error resolving fragment: "~{'/blocks/topbar' :: topbar}": template or fragment could not be resolved (template: "blocks/header" - line 3, col 10)
<div th:replace="/blocks/topbar :: .top-bar"></div>