拦截器
作者:互联网
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
public void addInterceptors(InterceptorRegistry registry) {
// /**表示拦截所有请求
String[] addPath = {"/**"};
// 放行getStudent和getUser两个请求:其中getUser请求没有对应的处理器
String[] excludePath = {"/getStudent","/getUser"};
registry.addInterceptor(new InterceptorByInterface()).addPathPatterns(addPath).excludePathPatterns(excludePath);
}
}
//通过实现HandlerInterceptor接口实现拦截,这个类需要注册
public class InterceptorByInterface implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
return true;
}
}
标签:InterceptorByInterface,拦截器,String,getUser,Override,public,HandlerInterceptor 来源: https://blog.csdn.net/weixin_44300245/article/details/110008841