编写拦截器
public class LoginInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
}
@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 {
}
}
对于前后端分离架构文章来源地址https://www.toymoban.com/news/detail-553896.html
- preHandle 会在方法执行前执行,按照拦截器顺序执行
- postHandle 会在方法return前执行,按照拦截器顺序逆序执行
- afterCompletion 方法return 之后执行 ,按照拦截器顺序逆序执行
拦截器注册
@Component
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
// order 拦截器的顺序,越小优先级越高
registry.addInterceptor(new LoginInterceptor()).order(1);
}
}
文章来源:https://www.toymoban.com/news/detail-553896.html
到了这里,关于springboot 拦截器的配置的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!