[HTML] 纯文本查看 复制代码
<html xmlns:th="http://www.thymeleaf.org"><!-- 引入命名空间 -->
<head>
<meta content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link th:href="@{bootstrap/css/bootstrap.min.css}" rel="stylesheet" /><!-- 通过使用 “@{}” 引用Web静态资源 -->
<link th:href="@{bootstrap/css/bootstrap-theme.min.css}" rel="stylesheet" />
</head>
<body>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">访问model</h3>
</div>
<div class="panel-body">
<span th:text="${boss.name}"></span><!-- 通过 “${}” 访问Mode中的属性 -->
</div>
</div>
<div th:if="${not #lists.isEmpty(users)}"><!-- 表达式 判断 List 集合是否为空 也支持SpringEL -->
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">列表</h3>
</div>
<div class="panel-body">
<ul class="list-group">
<li class="list-group-item" th:each="user{users}"><!-- th:each 遍历 集合 数据 user 为迭代变量;users为集合 -->
<span th:text="${user.name}"></span>
<span th:text="${user.age}"></span>
<button class="btn" thnclick="'getName(\'' + ${user.name} + '\');'">获得名字</button>
</li>
</ul>
</div>
</div>
</div>
<script th:src="@{jquery-1.10.2.min.js}" type="text/javascript"></script>
<script th:src="@{bootstrap/js/bootstrap.min.js}"></script>
<script th:inline="javascript">
var boss = [[${boss}]];<!-- 通过 “[[${}]]” 这个组合标识 访问 javascript 中Model -->
console.log(boss.name+"/"+boss.age)
function getName(name){
console.log(name);
}
</script>
</body>
</html>