1. 程式人生 > >SpringBoot中使用Thymeleaf常用功能(一):表示式訪問資料

SpringBoot中使用Thymeleaf常用功能(一):表示式訪問資料

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"></meta>
<title>thymeleaf示例</title>
<link rel="stylesheet" th:href="@{css/bootstrap.min.css}" />
<link rel="stylesheet" th:href="@{css/bootstrap-theme.min.css}"/> 
<script type="text/javascript" th:src="@{js/jquery-1.11.0.min.js}"></script>
<script type="text/javascript" th:src="@{js/bootstrap.min.js}"></script>
</head>
<body>
<div class="panel panel-primary">
<!-- .panel-heading 面板頭資訊。 -->
<div class="panel-heading">
<!-- .panel-title 面板標題。 -->
<h3 class="panel-title">Thymeleaf表示式訪問資料</h3>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-4">
<p><font color="red">${param.x}將返回一個名為x的請求引數</font></p><br/>
訪問頁面傳遞的引數:<span th:text="${param.loginName[0]}">登入名</span>&nbsp;<span th:text="${param.password[0]}">密碼</span>
<p><font color="red">${x}將返回儲存在Thymeleaf上下文中的變數x或作為請求Request作用範圍域中的屬性。</font></p><br/>
訪問request作用範圍域中的變數:<span th:text="${request1}">訪問成功</span><br/>
<p><font color="red">${session.x}將返回一個名為x的會話HttpSession作用範圍域中的屬性。</font></p><br/>
訪問session作用範圍域中的變數:<span th:text="${session.session1}">訪問成功</span><br/>
<p><font color="red">${application.x}將返回一個名為x的全域性ServletContext上下文作用範圍域中的屬性。</font></p><br/>
訪問application作用範圍域中的變數:<span th:text="${application.application1}">訪問成功</span><br/>
</div>
</div>
</div>
</body>
</html>