Skip to content

Commit

Permalink
조건부 평가
Browse files Browse the repository at this point in the history
  • Loading branch information
kiteB committed Sep 21, 2021
1 parent 644315e commit 1412c2d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public String each(Model model) {
return "basic/each";
}

@GetMapping("/condition")
public String condition(Model model) {
addUsers(model);
return "basic/condition";
}

private void addUsers(Model model) {
List<User> list = new ArrayList<>();
list.add(new User("userA", 10));
Expand Down
43 changes: 43 additions & 0 deletions thymeleaf-basic/src/main/resources/templates/basic/condition.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>if, unless</h1>
<table border="1">
<tr>
<th>count</th>
<th>username</th>
<th>age</th>
</tr>
<tr th:each="user, userStat : ${users}">
<td th:text="${userStat.count}">1</td>
<td th:text="${user.username}">username</td>
<td>
<span th:text="${user.age}">0</span>
<span th:text="'미성년자'" th:if="${user.age lt 20}"></span>
<span th:text="'미성년자'" th:unless="${user.age ge 20}"></span>
</td>
</tr>
</table>
<h1>switch</h1>
<table border="1">
<tr>
<th>count</th>
<th>username</th>
<th>age</th>
</tr>
<tr th:each="user, userStat : ${users}">
<td th:text="${userStat.count}">1</td>
<td th:text="${user.username}">username</td>
<td th:switch="${user.age}">
<span th:case="10">10살</span>
<span th:case="20">20살</span>
<span th:case="*">기타</span>
</td>
</tr>
</table>
</body>
</html>

0 comments on commit 1412c2d

Please sign in to comment.