惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
J
Java Code Geeks
V
V2EX
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
B
Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
美团技术团队
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
N
Netflix TechBlog - Medium
C
Check Point Blog
Recent Announcements
Recent Announcements
博客园 - Franky
博客园 - 叶小钗
T
Tailwind CSS Blog

祈雨的笔记

安全多方计算MPC spark原理解析 kueue执行源码分析 spark on k8s执行源码分析 spark-operator源码解析 系统压测遇到的缓存击穿问题 我的世界PC与安卓联机 蚂蚁金服流量投放平台的AIG改造 G1大对象致Old区占用率高 日志打印导致接口响应率下跌分析 Groovy加载类导致OOM分析 ERROR日志打印导致CPU满载 记OceanBase死锁超时 应用发版期间服务响应超时 Ark Serverless初探 系统优化复盘一二三 The user specified as a definer does not exist Kong网关初探 API网关选型调研 CPU火焰图常用工具 配置中心选型调研 root操作Nginx导致用户组错误 基于Proxifier使用代理 FastJSON字段智能匹配踩坑 Nacos初探 记一次Nginx服务器CPU满荷载故障 基于券系统分库分表的思考 limit不参与SQL成本计算致索引失效 Linux常用性能监控命令 golang低版本http2偶现400
springboot(9)整合thymeleaf
祈雨的笔记 · 2018-01-22 · via 祈雨的笔记

1、maven配置

springboot默认使用thymeleaf引擎,所以配置极其简单。
添加thymeleaf依赖:

1
2
3
4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2、创建thymeleaf模板

在src/main/resources下创建文件夹static、templates。
其中templates为thymeleaf模板默认路径,static为静态资源默认路径。

这里写图片描述

3、controller

1
2
3
4
5
6
7
8
9
10
11
@Controller
public class TestAction {

@RequestMapping("/index")
public String index(ModelMap map) {
map.put("title", "标题");


return "index";
}
}

4、thymeleaf模板:index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html>
<head lang="en">
<title>Index</title>
<link href="/css/index.css" rel="stylesheet" />
</head>
<body>
<div align="center">
<h1 id="title">
<span th:text="${title}"></span>
</h1>
</div>
</body>
</html>

5、设置不校验html标签

默认情况下,thymeleaf对html标签的格式要求严格。例如缺少封闭符号/,就会抛出异常并跳转到错误页。可通过以下配置关闭html标签校验。

5.1在springboot的配置文件中添加如下配置:

1
2
spring.thymeleaf.cache=false
spring.thymeleaf.mode=LEGACYHTML5

5.2、maven添加依赖

1
2
3
4
5
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.21</version>
</dependency>