2015-09-28 94 views
0

創建的樣本春天啓動的項目在STS和文件如下:Thymeleaf如何刪除重複的標籤

templetes \片段\的layout.html:

<!DOCTYPE html> 
<html> 
    <head> 
    <title layout:title-pattern="$DECORATOR_TITLE - $CONTENT_TITLE">Project Title</title> 
    <link th:replace="/fragments/style"/> 
    </head> 
    <body> 
    <div th:replace="/fragments/header"></div> 
    <div class="container" style="margin-top:80px;"> 
     <div layout:fragment="content"></div> 
    </div> 
    <div th:replace="/fragments/footer"></div> 
    <div th:replace="/fragments/js"></div> 
    </body> 
</html> 

templetes \片段\ style.html:

<!DOCTYPE html> 
<link rel="stylesheet" th:href="@{/webjars/bootstrap/3.3.5/css/bootstrap.min.css}"/> 

templetes \片段\ js.html:

<!DOCTYPE html> 
<script th:src="@{/webjars/jquery/2.1.4/jquery.min.js}"></script> 

templetes \片段\ header.html中:

<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
    <nav class="navbar navbar-inverse navbar-fixed-top"> 
    <div class="container"> 
     <p class="navbar-text">Project Header</p> 
    </div> 
    </nav> 
</body> 
</html> 

templetes \片段\ footer.html:

<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
    <nav class="navbar navbar-inverse navbar-fixed-bottom"> 
    <div class="container"> 
     <p class="navbar-text">Project Footer</p> 
    </div> 
    </nav> 
</body> 
</html> 

templetes \ index.html的:

<!DOCTYPE html> 
<html xmlns:th="http://www.thymeleaf.org" 
     xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="fragments/layout"> 
<head> 
    <title>Page Title</title> 
</head> 
<body> 
    <div layout:fragment="content"> 
    Page Content 
    </div> 
</body> 
</html> 

雖然瀏覽器渲染頁面正確地說,生成的源是重複標記爲:

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Project Title - Page Title</title> 
<link rel="stylesheet" href="/webjars/bootstrap/3.3.5/css/bootstrap.min.css" /> 
</head> 
    <body> 
<html> 
<head> 
</head> 
<body> 
    <nav class="navbar navbar-inverse navbar-fixed-top"> 
     <div class="container"> 
      <p class="navbar-text">Project Header</p> 
     </div> 
    </nav> 
</body> 
</html> 
    <div class="container" style="margin-top:80px;"> 
     <div> 
     Page Content 
    </div> 
    </div> 
<html> 
<head> 
</head> 
<body> 
    <nav class="navbar navbar-inverse navbar-fixed-bottom"> 
     <div class="container"> 
     <p class="navbar-text">Project Footer</p> 
     </div> 
    </nav> 
</body> 
</html> 
<script src="/webjars/jquery/2.1.4/jquery.min.js"></script> 
    </body> 
</html> 

請指導我刪除這些額外的標籤。 謝謝

回答

0

正如我所看到的,'重複'標記已經在你的頁眉和頁腳模板中。簡單地刪除它們(它們應該只是html片段),它應該是沒問題的!