thymeleaf_form : select box
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package hello.itemservice.web.form;
|
package hello.itemservice.web.form;
|
||||||
|
|
||||||
|
import hello.itemservice.domain.item.DeliveryCode;
|
||||||
import hello.itemservice.domain.item.Item;
|
import hello.itemservice.domain.item.Item;
|
||||||
import hello.itemservice.domain.item.ItemRepository;
|
import hello.itemservice.domain.item.ItemRepository;
|
||||||
import hello.itemservice.domain.item.ItemType;
|
import hello.itemservice.domain.item.ItemType;
|
||||||
@@ -10,6 +11,7 @@ import org.springframework.ui.Model;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -36,6 +38,15 @@ public class FormItemController {
|
|||||||
return ItemType.values();
|
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
|
@GetMapping
|
||||||
public String items(Model model) {
|
public String items(Model model) {
|
||||||
List<Item> items = itemRepository.findAll();
|
List<Item> items = itemRepository.findAll();
|
||||||
|
|||||||
@@ -62,6 +62,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</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="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button class="w-100 btn btn-primary btn-lg" type="submit">상품 등록</button>
|
<button class="w-100 btn btn-primary btn-lg" type="submit">상품 등록</button>
|
||||||
|
|||||||
@@ -67,6 +67,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</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="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button class="w-100 btn btn-primary btn-lg" type="submit">저장</button>
|
<button class="w-100 btn btn-primary btn-lg" type="submit">저장</button>
|
||||||
|
|||||||
@@ -69,6 +69,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</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="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button class="w-100 btn btn-primary btn-lg"
|
<button class="w-100 btn btn-primary btn-lg"
|
||||||
|
|||||||
Reference in New Issue
Block a user