thymeleaf_form : th:object, th:field
This commit is contained in:
@@ -32,7 +32,8 @@ public class FormItemController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/add")
|
@GetMapping("/add")
|
||||||
public String addForm() {
|
public String addForm(Model model) {
|
||||||
|
model.addAttribute("item", new Item());
|
||||||
return "form/addForm";
|
return "form/addForm";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,18 +18,18 @@
|
|||||||
<h2>상품 등록 폼</h2>
|
<h2>상품 등록 폼</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form action="item.html" th:action method="post">
|
<form action="item.html" th:action th:object="${item}" method="post">
|
||||||
<div>
|
<div>
|
||||||
<label for="itemName">상품명</label>
|
<label for="itemName">상품명</label>
|
||||||
<input type="text" id="itemName" name="itemName" class="form-control" placeholder="이름을 입력하세요">
|
<input type="text" id="itemName" th:field="*{itemName}" class="form-control" placeholder="이름을 입력하세요">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="price">가격</label>
|
<label for="price">가격</label>
|
||||||
<input type="text" id="price" name="price" class="form-control" placeholder="가격을 입력하세요">
|
<input type="text" id="price" th:field="*{price}" class="form-control" placeholder="가격을 입력하세요">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="quantity">수량</label>
|
<label for="quantity">수량</label>
|
||||||
<input type="text" id="quantity" name="quantity" class="form-control" placeholder="수량을 입력하세요">
|
<input type="text" id="quantity" th:field="*{quantity}" class="form-control" placeholder="수량을 입력하세요">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="my-4">
|
<hr class="my-4">
|
||||||
|
|||||||
@@ -18,22 +18,22 @@
|
|||||||
<h2>상품 수정 폼</h2>
|
<h2>상품 수정 폼</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form action="item.html" th:action method="post">
|
<form action="item.html" th:action th:object="${item}" method="post">
|
||||||
<div>
|
<div>
|
||||||
<label for="id">상품 ID</label>
|
<label for="id">상품 ID</label>
|
||||||
<input type="text" id="id" name="id" class="form-control" value="1" th:value="${item.id}" readonly>
|
<input type="text" id="id" name="id" th:field="*{id}" class="form-control" th:value="${item.id}" readonly>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="itemName">상품명</label>
|
<label for="itemName">상품명</label>
|
||||||
<input type="text" id="itemName" name="itemName" class="form-control" value="상품A" th:value="${item.itemName}">
|
<input type="text" id="itemName" class="form-control" th:field="*{itemName}">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="price">가격</label>
|
<label for="price">가격</label>
|
||||||
<input type="text" id="price" name="price" class="form-control" value="10000" th:value="${item.price}">
|
<input type="text" id="price" class="form-control" th:field="*{price}">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="quantity">수량</label>
|
<label for="quantity">수량</label>
|
||||||
<input type="text" id="quantity" name="quantity" class="form-control" value="10" th:value="${item.quantity}">
|
<input type="text" id="quantity" class="form-control" th:field="*{quantity}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="my-4">
|
<hr class="my-4">
|
||||||
|
|||||||
Reference in New Issue
Block a user