HTML标签
<head> <!-- meta 会报错-->
<meta charset="UTF-8" />
<link rel="stylesheet" th:href="${myName}+'/platform/common/s/1.1/global/global.css'"/>
<title>Title</title>
</head>
HTML标签中
<span th:text="'Welcome to our application, ' + ${myName} + '!'" />
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<body th:text="'Something went wrong: ' + ${status} + ' '+${error}" >
</body>
</html>
JavaScript 中
<script th:inline="javascript">
var myVar = [[${myName}]];
console.log(myVar);
const baseUrl = '[(${baseUrl})]';
const picUrl = '[(${picUrl})]';
</script>
使用前提
- 引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
- html 标签增加属性
xmlns:th="http://www.thymeleaf.org"
帮助文档
https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html https://www.kancloud.cn/cxr17618/springboot/428898 https://www.thymeleaf.org/doc/articles/springmvcaccessdata.html