我剛剛創建了一個新的Spring Boot v1.5項目,並面臨Thymeleaf Layout Dialect無法正常工作的問題。Spring Boot Thymeleaf Layout Dialect Not Working
我有我的build.gradle和它的類路徑中的依賴關係。
compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.1.2'
我有以下佈局文件
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8" />
<title>Default Template</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="" />
<meta name="description" content="" />
<meta name="title" content="" />
<link rel="stylesheet" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
<!-- header -->
<header th:include="shared/nav-menu :: menu-admin" />
<!-- page content -->
<th:block>
<section layout:fragment="content"></section>
</th:block>
</body>
</html>
並與內容文件:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default">
<head>
<title>Parameter Manager</title>
</head>
<body>
<section layout:fragment="content">
<h2>OMG I am on the page!</h2>
</section>
</body>
</html>
的HTML輸出content.html文件。它不按預期工作。標題和導航菜單應該是HTML輸出的一部分。此外,在頁面源中是不應該的。
如果你查看:源代碼,你還看到佈局:片段和佈局:裝飾器屬性,還是他們走了?您是否嘗試了其他的thymeleaf標籤來查看您的模板是否正在被評估? – Metroids
是的,在我的login.html不使用佈局方言thymeleaf工作正常。我前段時間使用過這個相同的設置,但當時它是Spring Boot 1.2或1.3,所以也許有些改變。 – greyfox