thymeleaf_form : radio box
This commit is contained in:
@@ -10,4 +10,8 @@ public enum ItemType {
|
||||
ItemType(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package hello.itemservice.web.form;
|
||||
|
||||
import hello.itemservice.domain.item.Item;
|
||||
import hello.itemservice.domain.item.ItemRepository;
|
||||
import hello.itemservice.domain.item.ItemType;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -30,6 +31,11 @@ public class FormItemController {
|
||||
return regions;
|
||||
}
|
||||
|
||||
@ModelAttribute("itemTypes")
|
||||
public ItemType[] itemTypes() {
|
||||
return ItemType.values();
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String items(Model model) {
|
||||
List<Item> items = itemRepository.findAll();
|
||||
|
||||
@@ -51,6 +51,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- radio button -->
|
||||
<div>
|
||||
<div>상품 종류</div>
|
||||
<div th:each="type : ${itemTypes}" class="form-check form-check-inline">
|
||||
<input type="radio" th:field="*{itemType}" th:value="${type.name()}" class="form-check-input">
|
||||
<label th:for="${#ids.prev('itemType')}" th:text="${type.description}" class="form-check-label">
|
||||
BOOK
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<button class="w-100 btn btn-primary btn-lg" type="submit">상품 등록</button>
|
||||
|
||||
@@ -56,6 +56,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- radio button -->
|
||||
<div>
|
||||
<div>상품 종류</div>
|
||||
<div th:each="type : ${itemTypes}" class="form-check form-check-inline">
|
||||
<input type="radio" th:field="*{itemType}" th:value="${type.name()}" class="form-check-input">
|
||||
<label th:for="${#ids.prev('itemType')}" th:text="${type.description}" class="form-check-label">
|
||||
BOOK
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<button class="w-100 btn btn-primary btn-lg" type="submit">저장</button>
|
||||
|
||||
@@ -58,6 +58,17 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- radio button -->
|
||||
<div>
|
||||
<div>상품 종류</div>
|
||||
<div th:each="type : ${itemTypes}" class="form-check form-check-inline">
|
||||
<input type="radio" th:field="${item.itemType}" th:value="${type.name()}" class="form-check-input" disabled>
|
||||
<label th:for="${#ids.prev('itemType')}" th:text="${type.description}" class="form-check-label">
|
||||
BOOK
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<button class="w-100 btn btn-primary btn-lg"
|
||||
|
||||
Reference in New Issue
Block a user