Skip to content

Commit 6646d7f

Browse files
committed
thymeleaf完结
1 parent 67acb3b commit 6646d7f

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

spring-boot-thymeleaf/src/main/java/com/springboot/springbootthymeleaf/controller/HelloController.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public String hello(HttpServletRequest request) {
4343

4444
map.put("list", list);
4545

46-
request.setAttribute("map", map);
46+
map.put("flag", true);
47+
48+
request.setAttribute("data", map);
4749
return "hello";
4850
}
4951
}

spring-boot-thymeleaf/src/main/resources/application.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ spring:
44
application:
55
name: spring-boot-thymleaf
66
thymeleaf:
7-
# 关闭thymeleaf缓存 开发时使用 否则没有实时画面
7+
# 关闭thymeleaf缓存 开发时使用 否则没有实时画面
88
cache: false
9-
# 检查模板是否存在,然后再呈现
9+
# 检查模板是否存在,然后再呈现
1010
check-template-location: true
1111
# Content-Type value.
1212
servlet:
1313
content-type: text/html
14-
# 启用MVC Thymeleaf视图分辨率
14+
# 启用MVC Thymeleaf视图分辨率
1515
enabled: true
1616
# Template encoding.
1717
encoding: UTF-8
18-
# 关闭严格模式
18+
# 关闭严格模式
1919
mode: LEGACYHTML5
2020
# Prefix that gets prepended to view names when building a URL.
2121
prefix: classpath:/templates/
2222
# Suffix that gets appended to view names when building a URL.
2323
suffix: .html
2424
mvc:
25-
# 指定静态资源处理路径
25+
# 指定静态资源处理路径
2626
static-path-pattern: /static/**
2727
view:
2828
suffix: .html

spring-boot-thymeleaf/src/main/resources/static/css/bootstrap.min.css

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring-boot-thymeleaf/src/main/resources/static/css/bootstrap.min.css.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,52 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html xmlns="http://www.w3.org/1999/xhtml"
3+
xmlns:th="http://www.thymeleaf.org">
34
<head>
45
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
57
<title>Hello Spring Boot</title>
8+
<link rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}">
69
</head>
710
<body>
11+
<div class="container">
12+
<div>用户信息:</div>
13+
<table class="table table-dark">
14+
<thead>
15+
<tr>
16+
<th scope="col">#</th>
17+
<th scope="col">姓名</th>
18+
<th scope="col">年龄</th>
19+
</tr>
20+
</thead>
21+
<tbody>
22+
<tr>
23+
<th scope="row" th:text="${data.user.id}"></th>
24+
<td th:text="${data.user.name}"></td>
25+
<td th:text="${data.user.age}"></td>
26+
</tr>
27+
</tbody>
28+
</table>
29+
<div>课程信息:</div>
30+
<table class="table table-dark">
31+
<thead>
32+
<tr>
33+
<th scope="col">#</th>
34+
<th scope="col">课程名称</th>
35+
<th scope="col">课程地点</th>
36+
</tr>
37+
</thead>
38+
<tbody>
39+
<tr th:each="course, iterStat : ${data.list}">
40+
<th scope="row" th:text="${course.id}"></th>
41+
<td th:text="${course.name}"></td>
42+
<td th:text="${course.address}"></td>
43+
</tr>
44+
</tbody>
45+
</table>
46+
47+
<div th:if="${data.flag == true}">如果 flag 为 true 你将可以看到这行字:)</div>
48+
49+
</div>
850

951
</body>
1052
</html>

0 commit comments

Comments
 (0)