2013-03-15 1 views
0

가정하자 나는 컨트롤러가 있습니다구성 오류 페이지

@Controller 

public class SomeController { 

    @RequestMapping(value = "{id}/object.do") 
    public String showObject(@PathVariable("id") Integer id, 
          HttpServletRequest request) { 
      //do smth 
      return "somePage"; 
     } 
} 

"ID가" "AAA/object.do"톰캣 같은 수 있지만, 문자열이 아닌 나에게 오류를 보여을 - " 클라이언트가 보낸 요청은 구문 상 올바르지 않습니다. "

"id"경로 변수의 유형이 잘못되었을 때만 표시되는 오류 페이지를 구성하는 방법이 있습니까?

당신은 (나는 그것이 TypeMismatchException 의심)

@ExceptionHandler(TypeMismatchException.class) 
public ModelAndView handleTypeMismatchException(TypeMismatchException ex) { 
    //TODO log 
    // Return something reasonable to the end user. 
    ... 
} 

평소 핸들러로, @ExceptionHandler는 기본적으로 거의 같은 기능을 가지고 있음을 유의하시기 바랍니다이 특정 오류에 대한 @ExceptionHandler으로이 문제를 처리 할 수 ​​

답변

1

:

@RequestMapping 주석으로 주석 처리 된 표준 컨트롤러 메소드와 마찬가지로 @ExceptionHandler 메소드의 메소드 인수와 반환 값은 매우 유연합니다.