[SpringBoot]Thymeleaf

dong's memory·2023년 12월 27일

Spring

목록 보기
4/11
#{}
<span th:text="#{test.id}"></span><br>
<span th:text="#{test.name}"></span><br>

apllication.properties 안에 있는 데이터
test1.context=dev (key)
test2.context=localhost:8080(value)

  • 해당 값 원하는 페이지로 이동
    Tag 활용 시 참조
		<ul>
			<li><a th:href="@{/hello}">basic url</a></li>
			<li><a th:href="@{/hello(param1=${param1}, param2=${param2})}">hello query param</a></li>
			<li><a th:href="@{/hello/{param1}/{param2}(param1=${param1}, param2=${param2})}">path variable</a></li>
			<li><a th:href="@{/hello/{param1}(param1=${param1}, param2=${param2})}">path variable + query parameter</a>
			</li>
		</ul>

HTML
1.7. th:href

<ul>
    <li><a th:href="@{/hello}">basic url</a></li>
    <li><a th:href="@{/hello(param1=${param1}, param2=${param2})}">hello query param</a></li>
    <li><a th:href="@{/hello/{param1}/{param2}(param1=${param1}, param2=${param2})}">path variable</a></li>
    <li><a th:href="@{/hello/{param1}(param1=${param1}, param2=${param2})}">path variable + query parameter</a></li>
</ul>

1.8. th:if, th:unless (if문)

<span th:if="${foodMap.food1} == '치킨'">치킨이다!</span>
<span th:unless="${foodMap.food1} == '치킨'">치킨이 아니다 ㅠㅠ</span>
  • foodMap.food1 == '치킨' => foodMap에 있는 food1이 치킨인가?
  • else -> unless 는 상단의 문법과 동일하게 써야함

값 세팅

<h2>th:with 사용 (c:set과 같은 느낌)</h2>
<span th:with="food='바뀐음식'"></span><br><br>

dateTime 출력(형식지정)

<hr>
default : <span th:text="${localDateTime}"></span><br>
yyyy-MM-dd HH:mm:ss : <span th:text="${#temporals.format(localDateTime, 'yyyy-MM-dd HH:mm:ss')}"></span> <br>
yyyy-MM-dd/a hh:mm : <span th:text="${#temporals.format(localDateTime, 'yyyy-MM-dd/a hh:mm')}"></span><br>
<hr>

attribute 활용

- th:classappend : <input type="text" class="text" th:attrappend="class= ' large'" /><br>
- checked o : <input type="checkbox" name="active" th:checked="true" /><br>
- checked x : <input type="checkbox" name="active" th:checked="false" /><br>
<br><br>
  • 스타일 변경 (span)
<style type="text/css">span{color: red}</style>
  • 빈칸에 힌트넣기
  • th:classappend :
th:classappend : <input type="text" class="text" th:attrappend="class= ' large'" placeholder="여기에 이름을 넣어주세요"/><br>
  • thymeleaf.html은 controller에 있는 매핑을 불러옴

0개의 댓글