Skip to content

Commit

Permalink
셀렉트 박스
Browse files Browse the repository at this point in the history
  • Loading branch information
kiteB committed Sep 22, 2021
1 parent 0a79dbd commit 329ee5a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hello.itemservice.web.form;

import hello.itemservice.domain.item.DeliveryCode;
import hello.itemservice.domain.item.Item;
import hello.itemservice.domain.item.ItemRepository;
import hello.itemservice.domain.item.ItemType;
Expand All @@ -10,6 +11,7 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -36,6 +38,15 @@ public ItemType[] itemTypes() {
return ItemType.values();
}

@ModelAttribute("deliveryCodes")
public List<DeliveryCode> deliveryCodes() {
List<DeliveryCode> deliveryCodes = new ArrayList<>();
deliveryCodes.add(new DeliveryCode("FAST", "빠른 배송"));
deliveryCodes.add(new DeliveryCode("NORMAL", "일반 배송"));
deliveryCodes.add(new DeliveryCode("SLOW", "느린 배송"));
return deliveryCodes;
}

@GetMapping
public String items(Model model) {
List<Item> items = itemRepository.findAll();
Expand Down
11 changes: 11 additions & 0 deletions form/src/main/resources/templates/form/addForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ <h2>상품 등록 폼</h2>
</div>
</div>

<!-- SELECT -->
<div>
<div>배송 방식</div>
<select th:field="*{deliveryCode}" class="form-select">
<option value="">==배송 방식 선택==</option>
<option th:each="deliveryCode : ${deliveryCodes}" th:value="${deliveryCode.code}"
th:text="${deliveryCode.displayName}">FAST</option>
</select>
</div>
<hr class="my-4">

<div class="row">
<div class="col">
<button class="w-100 btn btn-primary btn-lg" type="submit">상품 등록</button>
Expand Down
11 changes: 11 additions & 0 deletions form/src/main/resources/templates/form/editForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ <h2>상품 수정 폼</h2>
</div>
</div>

<!-- SELECT -->
<div>
<div>배송 방식</div>
<select th:field="*{deliveryCode}" class="form-select">
<option value="">==배송 방식 선택==</option>
<option th:each="deliveryCode : ${deliveryCodes}" th:value="${deliveryCode.code}"
th:text="${deliveryCode.displayName}">FAST</option>
</select>
</div>
<hr class="my-4">

<div class="row">
<div class="col">
<button class="w-100 btn btn-primary btn-lg" type="submit">저장</button>
Expand Down
12 changes: 12 additions & 0 deletions form/src/main/resources/templates/form/item.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ <h2 th:if="${param.status}" th:text="'저장 완료'"></h2>
</div>
</div>

<!-- SELECT -->
<div>
<div>배송 방식</div>
<select th:field="${item.deliveryCode}" class="form-select" disabled>
<option value="">==배송 방식 선택==</option>
<option th:each="deliveryCode : ${deliveryCodes}" th:value="${deliveryCode.code}"
th:text="${deliveryCode.displayName}">FAST</option>
</select>
</div>
<hr class="my-4">


<div class="row">
<div class="col">
<button class="w-100 btn btn-primary btn-lg"
Expand Down

0 comments on commit 329ee5a

Please sign in to comment.