thymeleaf入門 原

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>

使用前提

  1. 引入依賴
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
  1. 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章