springboot mvc添加拦截
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表示拦截掉
参考
- spring-boot学习笔记之Web拦截器
关键字:产品经理
版权声明
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处。如若内容有涉嫌抄袭侵权/违法违规/事实不符,请点击 举报 进行投诉反馈!