속성 값 설정

Mina Park·2022년 11월 17일
0

1. 기본개념

  • 타임리프는 주로 HTML 태그에 th:* 속성을 지정하는 방식으로 동작
  • 이 때, th:* 로 속성이 적용됨녀 기존 속성은 대체(없는 경우 새로 생성)

2. 속성설정/추가

  • 실제 작성한 코드
<input type="text" name="mock" th:name="userA" />
  • 타임리프 렌더링된 코드
<input type="text" name="userA" />

3. 적용예시

    @GetMapping("/attribute")
    public String attribute(Model model) {
        return "basic/attribute";
    }
<!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>

0개의 댓글