새소식

반응형
WEB/Thymeleaf

thymeleaf 에서 th:fragment 에 매개변수 넣는법

  • -
반응형

2024-03-06


사진: Unsplash 의 Pavel Golasowski


1. 방법

 

th:frgment를 호출할 th:replace  파트

 

<div class="test_wrap"
     th:replace="~{${'test.html'} :: testWrapFragment(value1=${value1})}">
</div>

 

호출할 th:frgment 이름 뒤에 괄호를 붙인뒤(매개변수명=${백엔드에서 넘긴 변수}) 를 같이 전달하면  th:frgment에


 

th:frgment 부분

 

th:frgment에서는

 

<div class="test_wrap" th:fragment="testWrapFragment">
    <div th:if="${value1 == 'a'}">
		value1 is a
    </div>
    <div th:if="${value1 == 'b'}">
		value1 is b
    </div>
</div>

메인 이미지 출처 : 사진: UnsplashPavel Golasowski  

 

반응형
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.