嗨,伙计们,我正在学习百里香叶,我不明白为什么它不起作用,我读了很多例子,我正确地做了它,但它不起作用。有人可以告诉我我在这里缺少什么吗?
这是我的布局:
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<link href="webjars/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<th:block layout:fragment="styles">
<nav class="navbar navbar-light bg-light">
<span class="navbar-brand mb-0 h1">Decorator Sample</span>
</nav>
<div class="container">
<div class="content">
<div layout:fragment="page_content"></div>
</div>
</div>
<script src="webjars/jquery/3.0.0/jquery.min.js"></script>
<script src="webjars/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<th:block layout:fragment="scripts">
这是我的索引:
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{_layout}">
<body>
<div layout:fragment="page_content">
</div>
</body>
我们需要将百里香叶入门包添加到您的春季靴子中:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
但是,从Spring Boot 2开始,这已经不够了。布局方言不是入门的一部分,我们需要自己添加它:
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
代码示例也使用 Bootstrap,因此也需要添加 webjar:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
你的pom中有这个吗.xml :
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>