[Thymeleaf] 타임리프에서 사용되는 다양한 문법 요소
2024. 1. 5. 10:17ㆍSpringBoot+JPA/Thymeleaf
반응형
🟢 변수 표현식 : ${...}
서버에서 계산한 값을 HTML에 출력하는 데 사용
<span th:text="${user.name}"> Name </span>
🟢 선택 변수 표현식 : *{...}
주로 폼 처리와 관련
폼 내부에서 객체의 속성에 접근할 때 사용
<input th:field="*{user.email}" />
🟢 메세지 표현식 : #{...}
다국어 지원 및 메시지 번역에 사용
메시지 소스에서 해당 메시지를 찾아 출력
<span th:text="#{welcome.message}">Welcome</span>
🟢 링크 URL 표현식 : @{...}
URL을 동적으로 생성할 때 사용
상대 경로나 절대 경로를 생성
<a th:href="@{/user/{id}(id=${user.id})}">User Profile</a>
🟢 조각 표현식 : ~{...}
조각 템플릿(fragment)을 참조할 때 사용
주로 다른 템플릿의 일부분을 재사용할 때 유용
<div th:replace="fragments/footer :: copyright"></div>
📌 Thymeleaf 참고 사이트
반응형
'SpringBoot+JPA > Thymeleaf' 카테고리의 다른 글
[Thymeleaf] 객체나 변수 간의 비교 / 동등 연산자 (0) | 2024.01.05 |
---|---|
[Thymeleaf] 타임리프 정의 및 사용 방법 (0) | 2024.01.04 |