어노테이션 사용하여 인터셉터 무시하기
개발중 인터셉터를 이용하여 postHandler 쪽에서 메뉴 리스트를 뷰로 보내주고있었다.
하지만 jsp단에서 ajax를 사용하는데 인터셉터를 계속 타다보니 null exception이 뜨는 상황…
ajax 부분은 별로 되지 않기때문에 어노테이션을 생성하여 인터셉터에서 제외시키기로 결정
따로 xml에 인터셉터 추가는 적지 않는다.
head 태그 사이에 추가하자
@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface NoMenuAnnotation{
//...
}
인터셉터에 어노테이션 제어부분 추가
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
HandlerMethod handlerMethod = (HandlerMethod) handler;
NoMenuAnnotation usingNoMenu = handlerMethod.getMethodAnnotation(NoMenuAnnotation.class);
if(usingNoMenu == null) {
}
super.postHandle(request, response, handler, modelAndView);
}
Leave a comment