thymeleaf - 입력 폼 처리

2dean·2023년 5월 15일
0

thymeleaf

목록 보기
1/1
post-thumbnail

입력폼 처리

th:object // 커맨드 객체 지정
*{...}    // 선택 변수식/ th:object 에서 선택한 객체에 접근 함
th:field  // HTML 태그의 id , name , value 속성을 자동으로 처리해준다.

랜더링 전

<input type="text" th:field="*{itemName}" />

랜더링 후

<input type="text" id="itemName" name="itemName" th:value="*{itemName}" />

객체 전달

th:object 를 적용하려면 먼저 해당 오브젝트 정보를 model 객체에 담아서 html쪽으로 넘겨주어야 한다.

html 에 thymeleaf 적용 예

<form action="item.html" th:action th:object="${item}" method="post">
	<div>
        <label for="itemName">상품명</label>
        <input type="text" id="itemName" th:field="*{itemName}" class="form-
        control" placeholder="이름을 입력하세요"> </div>
	<div>
        <label for="price">가격</label>
        <input type="text" id="price" th:field="*{price}" class="form-control" placeholder="가격을 입력하세요">
	</div>
	<div>
      <label for="quantity">수량</label>
      <input type="text" id="quantity" th:field="*{quantity}" class="form-
      control" placeholder="수량을 입력하세요">
    </div>
profile
냅다 써보는 공부의 흔적😇

1개의 댓글

comment-user-thumbnail
2023년 5월 21일

입력 폼 미쳤다

답글 달기