首页 > 代码库 > ControllerInterceptor
ControllerInterceptor
/*权限拦截
判断当前用户是否有权限访问该页面
说明:发起请求,进入拦截器连,运行所有拦截器的preHandle方法,
1、当preHandle返回false,从当前拦截器往回执行所有拦截器的afterCompletion方法,再退出拦截器连
2、当preHandle返回true,执行下一个拦截器,直到所有的拦截器执行完。再运行被拦截的Controller。
然后进入拦截器连,运行所有拦截器的postHandle方法,完后从最后一个拦截器往回执行所有拦截器的afterCompletion方法,
当有拦截器抛出异常,会从当前拦截器往回执行所有拦截器的afterCompletion方法*/
public class ControllerInterceptor extends HandlerInterceptorAdapter {
private static final Logger log=Logger.getLogger(ControllerInterceptor.class);
private List<String> excludedUrls;
@Overrider
public void afterCompletion(HttpServletRequest request,
HttpServletResponse response,Object handler,Exception ex) throws Exception{
Log.debug("-->afterCompletion");
super.afterCompletion(request,response,handler,ex);
}
@Overrider
public void postHandle(HttpServletRequest request,
HttpServletResponse response,Object handler,ModelAndView mav) throws Exception{
Log.debug("-->postHandle");
super.postHandle(request,response,handler,mav);
}
@Overrider
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response,Object handler) throws Exception{
Log.debug("-->preHandle");
//当前访问的链接
String currentUrl=request.getServletPath();
String currentRequestURI=request.getRequestURI();
Log.info("currentUrl-->"+currentRequestURI);
String requestUri=request.getRequestURI();
if(requestUri.equals("/etruck-webapp/web/auth/login"||
requestUri.contains("/etruck-webapp/web/css"||
requestUri.contains("/etruck-webapp/web/js")){
return super.preHandle(request,response,handler);
}else{
return super.preHandle(request,response,handler);
}
}
public List<String> getExcludeUrl(){
return excludedUrls;
}
public void setExcludeUrl(List<String> excludedUrls){
this.excludedUrls=excludedUrls;
}
public List<String> getExcludeUrls(){
return excludedUrls;
}
public void setExcludeUrls(List<String> excludedUrls){
this.excludedUrls=excludedUrls;
}
}
ControllerInterceptor