annotation으로 Controller구현시
- 작성자 :
- 명*민
- 작성일 :
- 2011-06-15 13:44:51
- 조회수 :
- 2,613
- 구분 :
- 공통컴포넌트
- 진행상태 :
- 완료
Q
안녕하세요.
항상 빠른 답변에 감사드립니다.
전자정부프레임워크 MVC 예제가 annotation으로 되어 있는데요,
어떤 공통된 처리(가령, 로그인 여부를 체크한다던지)에 대한 부분은
annotation으로 Controller 구현시에는 어떤 식으로 처리를 해야 하는지
궁금하여 문의 드립니다.
다양한 방법들이 존재하겠지만, 일반적으로 쓰이는 방법에 대해서 가이드를
해주시면 감사하겠습니다.
항상 빠른 답변에 감사드립니다.
전자정부프레임워크 MVC 예제가 annotation으로 되어 있는데요,
어떤 공통된 처리(가령, 로그인 여부를 체크한다던지)에 대한 부분은
annotation으로 Controller 구현시에는 어떤 식으로 처리를 해야 하는지
궁금하여 문의 드립니다.
다양한 방법들이 존재하겠지만, 일반적으로 쓰이는 방법에 대해서 가이드를
해주시면 감사하겠습니다.
A
안녕하세요.. 명준민님..
그런 경우는 대부분 interceptor를 통해 구현합니다.
interceptor는 호출되는 Controller 전 또는 후에.. 공통된 처리로직을 넣을 수 있습니다.
인증 확인 여부도 interceptor를 통해 대부분 처리됩니다.
interceptor 구현의 예는 다음과 같습니다.
public class AuthenticInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
Account account = (Account) WebUtils.getSessionAttribute(request, "UserAccount");
if(account!=null){
return true;
}else{
ModelAndView modelAndView = new ModelAndView("redirect:/login.do");
throw new ModelAndViewDefiningException(modelAndView);
}
}
}
설정은 다음 가이드를 참조하시면 되실 것 같습니다. (handlermapping에 등록됨)
http://www.egovframe.org/wiki/doku.php?id=egovframework:rte:ptl:handlermapping&s[]=interceptor
그럼.. 즐거운 하루되십시오.
감사합니다.
그런 경우는 대부분 interceptor를 통해 구현합니다.
interceptor는 호출되는 Controller 전 또는 후에.. 공통된 처리로직을 넣을 수 있습니다.
인증 확인 여부도 interceptor를 통해 대부분 처리됩니다.
interceptor 구현의 예는 다음과 같습니다.
public class AuthenticInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
Account account = (Account) WebUtils.getSessionAttribute(request, "UserAccount");
if(account!=null){
return true;
}else{
ModelAndView modelAndView = new ModelAndView("redirect:/login.do");
throw new ModelAndViewDefiningException(modelAndView);
}
}
}
설정은 다음 가이드를 참조하시면 되실 것 같습니다. (handlermapping에 등록됨)
http://www.egovframe.org/wiki/doku.php?id=egovframework:rte:ptl:handlermapping&s[]=interceptor
그럼.. 즐거운 하루되십시오.
감사합니다.