타임리프 블록 사용의 간단한 예시 보고 넘어가 보자.
<block.html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<th:block th:each="user : ${users}">
<div>
사용자 이름1 <span th:text="${user.username}"></span>
사용자 나이1 <span th:text="${user.age}"></span>
</div>
<div>
요약 <span th:text="${user.username} + ' / ' + ${user.age}"></span>
</div>
</th:block>
</body>
</html>
블록 사용 방법은 <th:block>로 블록을 열어주고 </th:block>으로 닫아준다
위 코드처럼 <th: block th: each = "user : ${users}"> 를 쓰면 블로 안의 코드가 반복문으로 돌아간다.
<실행결과>
'BackEnd > Thymeleaf' 카테고리의 다른 글
타임리프 - 템플릿 레이아웃 (0) | 2024.07.21 |
---|---|
타임리프 - 템플릿 조각 (0) | 2024.07.21 |
타임리프 - 조건문 (0) | 2024.07.19 |
타임리프-반복문 (0) | 2024.07.19 |
타임리프-속성값 설정 (0) | 2024.07.19 |