Thymeleaf reads the objects in the model
Student.java
package com.sxt.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student {
private Integer id;
private String name;
private String sex;
private Integer age;
private String phone;
private Date birth;
private Double money;
}
showOneStudent.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
<legend>学生信息</legend>
</fieldset>
<div style="padding: 20px; background-color: #F2F2F2;">
<div class="layui-row layui-col-space15">
<div class="layui-col-md6">
<div class="layui-card">
<div class="layui-card-body">
<span>学生编号:</span><span th:text="${student.id}"></span><br>
<span>学生姓名:</span><span th:text="${student.name}"></span><br>
<span>学生年龄:</span><span th:text="${student.age}"></span><br>
<span>学生性别:</span><span th:text="${student.sex}"></span><br>
<span>学生生日:</span><span th:text="${student.birth}"></span><br>
<span>学生生日:</span><span th:text="${#dates.format(student.birth,'yyyy-MM-dd HH:mm:ss')}"></span><br>
<span>学生电话:</span><span th:text="${student.phone}"></span><br>
<span>学生存款:</span><span th:text="${#numbers.formatDecimal(student.money,22,8)}"></span><br>
</div>
</div>
</div>
</div>
</div>
<script src="/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
var id=[[${student.id}]];
var name="[[${student.name}]]";
alert(id+"----"+name);
</script>
</body>
</html>
Thymeleaf reads collections in model
showAllStudent.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!--<link rel="stylesheet" href="/layui/css/layui.css" media="all">-->
<link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
<legend>学生信息</legend>
</fieldset>
<div style="padding: 20px; background-color: #F2F2F2;">
<div class="layui-row layui-col-space15">
<div class="layui-col-md3" th:each="student:${students}">
<div class="layui-card">
<div class="layui-card-body">
<span>学生编号:</span><span th:text="${student.id}"></span><br>
<span>学生姓名:</span><span th:text="${student.name}"></span><br>
<span>学生年龄:</span><span th:text="${student.age}"></span><br>
<span>学生性别:</span><span th:text="${student.sex}"></span><br>
<span>学生生日:</span><span th:text="${student.birth}"></span><br>
<span>学生生日:</span><span th:text="${#dates.format(student.birth,'yyyy-MM-dd HH:mm:ss')}"></span><br>
<span>学生电话:</span><span th:text="${student.phone}"></span><br>
<span>学生存款:</span><span th:text="${#numbers.formatDecimal(student.money,22,8)}"></span><br>
</div>
</div>
</div>
</div>
</div>
<!--<script src="/layui/layui.js" charset="utf-8"></script>-->
<script th:src="@{/layui/layui.js}" charset="utf-8"></script>
</body>
</html>
Themeleaf takes value in js
Access message with parameters
The use of ThymeleafObjects [take the value of the three major domains]
showObjects.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
model:<span th:text="${name}"></span><br>
request:<span th:text="${#httpServletRequest.getAttribute('name')}"></span><br>
session:<span th:text="${#httpSession.getAttribute('name')}"></span><br>
session:<span th:text="${#session.getAttribute('name')}"></span><br>
session:<span th:text="${session.name }"></span><br>
servletContext:<span th:text="${#servletContext.getAttribute('name') }"></span><br>
我的国家:<span th:text="${#locale.displayCountry}"></span>-<span th:text="${#locale.country}"></span><br>
我的母语:<span th:text="${#locale.displayLanguage}"></span>-<span th:text="${#locale.language}"></span><br>
</body>
</html>
Thymeleaf link pass value