springboot_validation : bean validation - http message converter
This commit is contained in:
@@ -0,0 +1,30 @@
|
|||||||
|
package hello.itemservice.web.validation;
|
||||||
|
|
||||||
|
import hello.itemservice.web.validation.form.ItemSaveForm;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/validation/api/items")
|
||||||
|
public class ValidationItemApiController {
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
public Object addItem(@RequestBody @Validated ItemSaveForm form, BindingResult bindingResult) {
|
||||||
|
|
||||||
|
log.info("API 컨트롤러 호출");
|
||||||
|
|
||||||
|
if(bindingResult.hasErrors()) {
|
||||||
|
log.info("검증 오류 발생 errors={}", bindingResult);
|
||||||
|
return bindingResult.getAllErrors();
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("성공 로직 실행행");
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user