each
This commit is contained in:
@@ -90,6 +90,20 @@ public class BasicController {
|
|||||||
return "basic/attribute";
|
return "basic/attribute";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/each")
|
||||||
|
public String each(Model model) {
|
||||||
|
addUsers(model);
|
||||||
|
return "basic/each";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addUsers(Model model) {
|
||||||
|
List<User> list = new ArrayList<>();
|
||||||
|
list.add(new User("userA", 10));
|
||||||
|
list.add(new User("userB", 20));
|
||||||
|
list.add(new User("userC", 30));
|
||||||
|
model.addAttribute("users", list);
|
||||||
|
}
|
||||||
|
|
||||||
@Component("helloBean")
|
@Component("helloBean")
|
||||||
static class HelloBean {
|
static class HelloBean {
|
||||||
public String hello(String data) {
|
public String hello(String data) {
|
||||||
|
|||||||
44
thymeleaf/src/main/resources/templates/basic/each.html
Normal file
44
thymeleaf/src/main/resources/templates/basic/each.html
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>기본 테이블</h1>
|
||||||
|
<table border="1">
|
||||||
|
<tr>
|
||||||
|
<th>username</th>
|
||||||
|
<th>age</th>
|
||||||
|
</tr>
|
||||||
|
<tr th:each="user : ${users}">
|
||||||
|
<td th:text="${user.username}">username</td>
|
||||||
|
<td th:text="${user.age}">0</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h1>반복 상태 유지</h1>
|
||||||
|
<table border="1">
|
||||||
|
<tr>
|
||||||
|
<th>count</th>
|
||||||
|
<th>username</th>
|
||||||
|
<th>age</th>
|
||||||
|
<th>etc</th>
|
||||||
|
</tr>
|
||||||
|
<tr th:each="user, userStat : ${users}">
|
||||||
|
<td th:text="${userStat.count}">username</td>
|
||||||
|
<td th:text="${user.username}">username</td>
|
||||||
|
<td th:text="${user.age}">0</td>
|
||||||
|
<td>
|
||||||
|
index = <span th:text="${userStat.index}"></span>
|
||||||
|
count = <span th:text="${userStat.count}"></span>
|
||||||
|
size = <span th:text="${userStat.size}"></span>
|
||||||
|
even? = <span th:text="${userStat.even}"></span>
|
||||||
|
odd? = <span th:text="${userStat.odd}"></span>
|
||||||
|
first? = <span th:text="${userStat.first}"></span>
|
||||||
|
last? = <span th:text="${userStat.last}"></span>
|
||||||
|
current = <span th:text="${userStat.current}"></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user