Thymeleaf读取model⾥⾯的对象Thymeleaf读取model⾥⾯的
集合The。。。
Thymeleaf读取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="">
<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" >
<legend>学⽣信息</legend>
</fieldset>
<div >
<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.,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读取model⾥⾯的集合
showAllStudent.html
<!DOCTYPE html>
<html lang="en" xmlns:th="">
<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" >
<legend>学⽣信息</legend>
</fieldset>
<div >
<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.,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在js中取值
访问带参数的消息thyme
ThymeleafObjects的使⽤[取三⼤作域的值]
showObjects.html
<!DOCTYPE html>
<html lang="en" xmlns:th="">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
model:<span th:text="${name}"></span><br>
request:<span th:text="${#Attribute('name')}"></span><br>
session:<span th:text="${#Attribute('name')}"></span><br>
session:<span th:text="${#Attribute('name')}"></span><br>
session:<span th:text="${session.name }"></span><br>
servletContext:<span th:text="${#Attribute('name') }"></span><br>
我的国家:<span th:text="${#locale.displayCountry}"></span>-<span th:text="${#untry}"></span><br>我的母语:<span th:text="${#locale.displayLanguage}"></span>-<span th:text="${#locale.language}"></span><br>
</body>
</html>
Thymeleaf链接传值
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论