-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bean Validatior - api validation , Request Body 검증
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...alidation/src/main/java/hello/itemservice/web/validation/ValidationItemApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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("검증 오류 발생 = " + bindingResult); | ||
return bindingResult.getAllErrors(); | ||
} | ||
|
||
log.info("성공 로직 실행"); | ||
return form; | ||
} | ||
|
||
} |