티스토리 뷰
반응형
HTML의 태그가 아닌 오직 타임 리프만이 제공하는 유일한 자체 태그인 Block tag에 대해 살펴보고자 한다
Synthetic th:block
타임리프가 블록태그를 만든 이유는 주로 반복문에서 발생하는 문제점 때문인데
예를 들어 아래와 같이 두 개의 div 태그를 반복문으로 같이 돌리고 싶다면 매우 난감한 상황이 온다
<!-- th:block 미사용 -->
<div th:each="user : ${userList}">
<span th:text="user.username}">username</span>
<span th:text="user.age}">age</span>
</div>
<div th:each="user : ${userList}">
<span th:text="${user.username} + ' & ' + ${user.age}">username&age</span>
</div>
이때 th:block 말 그대로 하나의 블록 처리를 하여 반복문을 돌리면 굉장히 간단하게 해결이 된다
<!-- th:block 사용 -->
<th:block th:each="user : ${userList}">
<div>
<span th:text="user.username}">username</span>
<span th:text="user.age}">age</span>
</div>
<div>
<span th:text="${user.username} + ' & ' + ${user.age}">username&age</span>
</div>
</th:block>
th:block은 렌더링 될 때 사라지며 웹브라우저에는 본래 의도하던 두 개의 <div> 태그의 반복문 결과만 남게 된다
더보기
개인 학습을 위해 작성되는 글입니다.
제가 잘못 알고 있는 점에 대한 지적 / 더 나은 방향에 대한 댓글을 환영합니다.
참조 링크:
https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-mvc-2/dashboard
https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html
반응형
'WEB > Template Engine' 카테고리의 다른 글
[Thymeleaf] Templates Fragments (템플릿 조각) (0) | 2021.09.02 |
---|---|
[Thymeleaf] JavaScript Inlining (자바스크립트 인라인) (1) | 2021.09.02 |
[Thymeleaf] Comments (주석) (0) | 2021.09.02 |
[Thymeleaf] Conditional Evaluation (조건부 평가) (0) | 2021.09.01 |
[Thymeleaf] Object Binding (객체 바인딩) (0) | 2021.09.01 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- ExceptionHandlerExceptionResolver
- spring
- 제이쿼리 기본 선택자
- 제이쿼리란
- @ResponseStatus
- cookie
- 제이쿼리 탐색선택자
- Spring TypeConverter
- Cache
- Spring Container
- 캐시
- Spring MVC
- 맨코
- Spring API Error
- Session
- maenco
- DefaultHandlerExceptionResolver
- application/x-www-form-urlencoded
- @ExceptionHandlere
- DTO와 VO의 차이
- 세션
- 제이쿼리 직접 선택자
- uri
- OOP
- 제이쿼리 인접 관계 선택자
- jQuery 직접 선택자
- ResponseStatusExeceptionResolver
- 제이쿼리 위치탐색선택자
- http
- 쿠키
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
글 보관함