diff --git a/thymeleaf_form/src/main/java/hello/itemservice/web/form/FormItemController.java b/thymeleaf_form/src/main/java/hello/itemservice/web/form/FormItemController.java index c18e9f0f..43d76c1f 100644 --- a/thymeleaf_form/src/main/java/hello/itemservice/web/form/FormItemController.java +++ b/thymeleaf_form/src/main/java/hello/itemservice/web/form/FormItemController.java @@ -9,7 +9,9 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; @Slf4j @Controller @@ -19,6 +21,15 @@ public class FormItemController { private final ItemRepository itemRepository; + @ModelAttribute("regions") + public Map regions() { + Map regions = new LinkedHashMap<>(); + regions.put("SEOUL", "서울"); + regions.put("BUSAN", "부산"); + regions.put("JEJU", "제주"); + return regions; + } + @GetMapping public String items(Model model) { List items = itemRepository.findAll(); @@ -30,6 +41,7 @@ public class FormItemController { public String item(@PathVariable long itemId, Model model) { Item item = itemRepository.findById(itemId); model.addAttribute("item", item); + return "form/item"; } @@ -42,6 +54,7 @@ public class FormItemController { @PostMapping("/add") public String addItem(@ModelAttribute Item item, RedirectAttributes redirectAttributes) { log.info("item.open = {}", item.getOpen()); + log.info("item.region = {}", item.getRegions()); Item savedItem = itemRepository.save(item); redirectAttributes.addAttribute("itemId", savedItem.getId()); redirectAttributes.addAttribute("status", true); diff --git a/thymeleaf_form/src/main/resources/templates/form/addForm.html b/thymeleaf_form/src/main/resources/templates/form/addForm.html index aa8bda4f..1ca23bd6 100644 --- a/thymeleaf_form/src/main/resources/templates/form/addForm.html +++ b/thymeleaf_form/src/main/resources/templates/form/addForm.html @@ -42,6 +42,15 @@ + +
+
등록 지역
+
+ + +
+
+
diff --git a/thymeleaf_form/src/main/resources/templates/form/editForm.html b/thymeleaf_form/src/main/resources/templates/form/editForm.html index beb44ec2..37f5498b 100644 --- a/thymeleaf_form/src/main/resources/templates/form/editForm.html +++ b/thymeleaf_form/src/main/resources/templates/form/editForm.html @@ -47,6 +47,15 @@
+ +
+
등록 지역
+
+ + +
+
+
diff --git a/thymeleaf_form/src/main/resources/templates/form/item.html b/thymeleaf_form/src/main/resources/templates/form/item.html index c6a94a2c..14a7c763 100644 --- a/thymeleaf_form/src/main/resources/templates/form/item.html +++ b/thymeleaf_form/src/main/resources/templates/form/item.html @@ -49,6 +49,15 @@
+ +
+
등록 지역
+
+ + +
+
+