diff --git a/springboot_validation/src/main/java/hello/itemservice/web/validation/ValidationItemControllerV2.java b/springboot_validation/src/main/java/hello/itemservice/web/validation/ValidationItemControllerV2.java index f468add8..8f245a9f 100644 --- a/springboot_validation/src/main/java/hello/itemservice/web/validation/ValidationItemControllerV2.java +++ b/springboot_validation/src/main/java/hello/itemservice/web/validation/ValidationItemControllerV2.java @@ -144,6 +144,10 @@ public class ValidationItemControllerV2 { @PostMapping("/add") public String addItemV4(@ModelAttribute Item item, BindingResult bindingResult, RedirectAttributes redirectAttributes, Model model) { + if (bindingResult.hasErrors()) { + return "validation/v2/addForm"; + } + // 검증 로직 ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "itemName", "required"); // if (!StringUtils.hasText(item.getItemName())) { diff --git a/springboot_validation/src/main/resources/errors.properties b/springboot_validation/src/main/resources/errors.properties index fbc7a891..00920b56 100644 --- a/springboot_validation/src/main/resources/errors.properties +++ b/springboot_validation/src/main/resources/errors.properties @@ -32,4 +32,8 @@ max.java.lang.Integer = {0} 까지의 숫자를 허용합니다. required = 필수 값 입니다. min= {0} 이상이어야 합니다. range= {0} ~ {1} 범위를 허용합니다. -max= {0} 까지 허용합니다. \ No newline at end of file +max= {0} 까지 허용합니다. + +#추가 +typeMismatch.java.lang.Integer=숫자를 입력해주세요. +typeMismatch=타입 오류입니다. \ No newline at end of file