[ Thymeleaf ] th : attribute 속성 ( 설명 ) > SPRINGBOOT

본문 바로가기

사이트 내 전체검색

뒤로가기 SPRINGBOOT

[ Thymeleaf ] th : attribute 속성 ( 설명 )

페이지 정보

작성자 관리자 작성일 24-06-06 14:46 조회 619 댓글 0

본문

타임리프는 주로 HTML 태그의 th: xxx 속성을 치환하는 방식으로 동작한다.
이때 기존 속성이 없으면 새로 만들어서 제공한다.
이전 글들에서 th:text 또는 th:href 또한 이런 속성을 치환하는 방식으로 동작한 것이다.


01. th:attrappend : 속성 값의 뒤에 값을 추가한다 (append)
뒤에 붙기 때문에 꼭 앞에 띄어쓰기를 해주어야 정상적으로 append 된다

<!-- attrappend -->
<input type="text" class="text" th:attrappend="class=' large'"/>

<!-- 결과 -->
<input type="text" class="text large"/>


02. th:attrprepend : 속성 값의 앞에 값을 추가한다 (prepend)
앞에 붙기 때문에 꼭 뒤에 띄어쓰기를 해주어야 정상적으로 prepend 된다

<!-- attrprepend -->
<input type="text" class="text" th:attrprepend="class='large '"/>

<!-- 결과 -->
<input type="text" class="large text"/>

댓글목록 0

등록된 댓글이 없습니다.


Copyright © dancePKT. All rights reserved.
PC 버전으로 보기