spring-mvc - Thymeleaf 布局装饰器不起作用
问题描述
嗨,伙计们,我正在学习百里香,我不明白为什么它不起作用我读了很多例子,我做对了,但它不起作用。有人可以告诉我我在这里缺少什么吗?
这是我的布局:
<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>
解决方案
我们需要将 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>
推荐阅读
- python - 如何将集合和单个值映射到函数
- prestashop-1.6 - prestashop1.6 中的 URL 中断
- python - 更改列表列表并在 python 2.7 中创建一个新列表
- java - 适配器 - 微服务或依赖项
- javascript - 修改将包装类添加到 iframe 的脚本 - 使其仅适用于某些域
- python - 如何使用 Report Lab 在 Python 中的画布上绘制表格
- sql - 如何将嵌套的 JSON 导入 SQL Server 表?
- algorithm - 查找从一点可见的网格三角形
- mqtt - 使用 mqtt QoS 2 发布消息时,会丢失吗?
- kotlin - 转换可变列表
到可变列表