2017-02-03 90 views
2

我刚刚创建了一个新的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输出的一部分。此外,在页面源中是不应该的。

+0

如果你查看:源代码,你还看到布局:片段和布局:装饰器属性,还是他们走了?您是否尝试了其他的thymeleaf标签来查看您的模板是否正在被评估? – Metroids

+0

是的,在我的login.html不使用布局方言thymeleaf工作正常。我前段时间使用过这个相同的设置,但当时它是Spring Boot 1.2或1.3,所以也许有些改变。 – greyfox

回答

2

显然,Thymeleaf Layout Dialect的最新版本不适用于Spring Boot 1.5。使用1.2.9版本,并按预期工作。

compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '1.2.9' 
+0

你可以使用2.1.2来覆盖spring-boot的依赖,就像https://github.com/rajadilipkolli/springsecuredthymeleafapp/blob/master/build.gradle#L21-L24 – rajadilipkolli

相关问题