嗨,大家好我学习百里香,我不明白为什么它不工作我读了很多例子,我做得很正确,但它不起作用。有人能告诉我我在这里失踪了吗?
这是我的布局:
<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>
答案 0 :(得分:1)
Did you have this in your pom.xml :
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
答案 1 :(得分:1)
我们需要将Thymeleaf入门包添加到您的Spring Boot pom:
<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>