스프링 예외처리 @ExceptionHandler, @ControllerAdvice 예제
스프링 예외처리를 할 때에는 @ExceptionHandler를 많이 사용한다. controller에서 @ExceptionHandler를 통해 메소드를 정의해주면 오류 발생시 메소드를 자동으로 호출해준다. (이때 사용하는 jsp를 오류 페이지용으로 만들어주면 된다) ex) 네이버 오류페이지 자 이제 @ExceptionHandler에 대해서 알아보자. 컨트롤러 코드를 구성해보자. @Controller public class TestController { @GetMapping("/test1") public String test1(Model model) { int[] array1 = {10, 20, 30}; //model.addAttribute("array1", array1[0]); model.addAttrib..
Spring
2022. 2. 7. 22:50