extends WebMvcConfigurerAdapter
@Configuration
public class InterceptorConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new AuthInterceptor());
}
}
implements HandlerInterceptor
public class AuthInterceptor implements HandlerInterceptor{
private static final Logger logger = LoggerFactory.getLogger(UserSecurityInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String uri = request.getRequestURI();
logger.info("intercept {}",uri);
//true表示继续往下,false表示拦截掉
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}
true表示继续往下,false表示拦截掉
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。