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