thymeleaf_form : radio box

This commit is contained in:
haerong22
2021-07-12 19:15:54 +09:00
parent 574cf622f7
commit ccc730a6d2
5 changed files with 43 additions and 0 deletions

View File

@@ -10,4 +10,8 @@ public enum ItemType {
ItemType(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}

View File

@@ -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();

View File

@@ -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>

View File

@@ -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>

View File

@@ -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"