피할 수 없다면 즐기자! 스프링부트 너.. 뭐 돼?
<span th:text="'hello'"></span>
<span th:text="hello"></span>
<!--
<span th:text="hello world"></span> (오류)
-->
<span th:text="'hello world'"></span>
(gt), <(lt), >=(ge), <=(le), !(not), ==(eq), !=(neq, ne)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<ul>
<li>비교 연산
<ul>
<li> 1 > 10 = <span th:text="1 > 10"></span></li>
<li> 1 > 10 = <span th:text="1 gt 10"></span></li>
<li> 1 >= 10 = <span th:text="1 >= 10"></span></li>
<li> 1 ge 10 = <span th:text="1 ge 10"></span></li>
<li> 1 == 10 = <span th:text="1 eq 10"></span></li>
<li> 1 != 10 = <span th:text="1 neq 10"></span></li>
</ul>
</li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<ul>
<li>조건식
<ul>
<li>(10 % 2 == 0) ? '짝수':'홀수' ==
<span th:text="(10 % 2 == 0) ? '짝수':'홀수'"></span>
</li>
</ul>
</li>
</ul>
서버로부터 'data'의 값을 전달받아 타임리프로 그 값을 전달받았다고 가정했어요.
<!-- 삼항 연산자 -->
<span th:text="${data}" ? ${data} : '데이터가 없습니다.' ></span>
<!-- Elvis 연산자 -->
<span th:text="${data}" ?: '데이터가 없습니다.' ></span>
삼항 연산자는 data의 변수가 값이 있으면 참, 값이 없으면 거짓 곧 '데이터가 없습니다.' 를 출력해요. Elvis 연산자는 동일하게 작동하지만 참일때의 조건을 생략한 연산자 에요.
<!-- th:value가 기본 value보다 우선 순위를 가지며 사이트 출력시에 '버튼뿅'이 value 값으로 보여지게 된다.-->
<button type="submit" value="버튼" th:value="버튼뿅" />
<tr th:each="user, userStat : ${users}">
userStat
- index : 0 부터 시작하는 값
- count : 1 부터 시작하는 값
- size : 전체 사이즈
- even, odd : 홀, 짝 여부(Boolean)
- first, last : 처음, 마지막 여부(boolean)
- current : 현재 객체
<th:block>은 HTML태그가 아닌 타임리프의 유일한 자체 태그에요.
<script th:inline="javascipt">
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<table border="1">
<thead>
<tr>
<th>번호</th>
<th>이름</th>
</tr>
</thead>
<tbody>
<tr th:object="${Item}">
<td th:text="*{itemId}"></td>
<td th:text="*{itemName}"></td>
</tr>
</tbody>
</table>
</body>
</html>
출처
https://media.giphy.com/media/kyUIknbbDNvID5XzU4/giphy.gif
https://media.giphy.com/media/A6aHBCFqlE0Rq/giphy.gif