템플릿 엔진 중 하나, html 확장자

태그의 속성을 추가하는 방식

<html xmlns:th="http://www.thymeleaf.org">

 

● 표현식

1. 변수식 : ${ }

2. 선택변수식 : *{ }

 - 객체의 변수 출력

3. 메시지식 : #{ }

 - properties 출력

4. 링크식 : @{ }

 

● 문법 : 태그안에 < th:속성 = "${  }" >

- text : 출력

- if, unless : if-else문

<p th:if="${check}" th:text="${num} + ' : ' + ${trueVal}">true</p>
<p th:unless="${check}" th:text="${num} + ' : ' + ${falseVal}">false</p>

 

- switch, case : switch-case문

<div th:switch="${num}">
    <p th:case="1" th:text="one">1</p>
    <p th:case="2" th:text="two">2</p>
    <p th:case="*">?</p>
</div>

 

- each : 반복문

<p th:each="user:${users}" th:text="${user.name}"></p> 

 

- with : 변수지정

<p th:with="authType = ${user.authType}+' Type'" th:text="${authType}"></p>

 

- value : element의 value값 지정

<input type="text" name="writer" title="이름 입력" th:value="${result.wrtier}" />

 

- block : 임의의 블럭을 지정 ex) div

<th:block th:each="user : ${users}">
    <p th:text="${user.login}"></p>
    <p th:text="${user.name}"></p>
</th:block>

브라우저에서는 인식하지 못함. (개발자 도구로 확인하면 보여지지 않음)

 

'Framework > Spring' 카테고리의 다른 글

[Thymeleaf] 타임리프 template layout  (0) 2020.12.03
JPA  (0) 2020.12.02
Xml과 Java Config  (0) 2020.10.06
JUnit  (0) 2020.10.02
Maven, Spring 프로젝트 생성시 설정  (0) 2020.10.01

+ Recent posts