BackEnd/Thymeleaf

타임리프-속성값 설정

연향동큰손 2024. 7. 19. 17:17

타임리프는 속성값을 th:*로 지정한다.

th:*로 속성을 적용하면 기존 속성을 대체한다.

 

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>속성 설정</h1>
<input type="text" name="mock" th:name="userA" />

<h1>속성 추가</h1>
- th:attrappend = <input type="text" class="text" th:attrappend="class=' large'" /><br/>
- th:attrprepend = <input type="text" class="text" th:attrprepend="class='large '" /><br/>
- th:classappend = <input type="text" class="text" th:classappend="large" /><br/>

<h1>checked 처리</h1>
- checked o <input type="checkbox" name="active" th:checked="true" /><br/>
- checked x <input type="checkbox" name="active" th:checked="false" /><br/>
- checked=false <input type="checkbox" name="active" checked="false" /><br/>

</body>
</html>

 

서버에서 소스코드 확인 결과

 

소스코드를 보면 다 th:로 대체 된것을 확인할 수 있다.

 

<속성 추가>

th:attrappend  : 속성 값의 뒤에 값을 추가한다.

th:attrprepend  : 속성 값의 앞에 값을 추가한다.

th:classappend : class 속성에 자연스럽게 추가한다.

 

 

<checked 처리>

 th:checked="false"

위와 같이 코드를 작성하면 checked값이 false인 경우 checked 속성 자체를 제거한다.

 

'BackEnd > Thymeleaf' 카테고리의 다른 글

타임리프 - 조건문  (0) 2024.07.19
타임리프-반복문  (0) 2024.07.19
타임리프 - 리터럴  (0) 2024.07.16
타임리프-URL 링크  (0) 2024.07.16
타임리프-기본객체  (0) 2024.07.16