zoukankan      html  css  js  c++  java
  • springboot拦截器

    WebConfig.java:

    package cn.ted.config;
    
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    
    import cn.ted.intercept.LoginInterceptor;
    
    @Configuration
    public class WebConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
    
            // 需要拦截的路径
    
            String[] addPathPatterns = { "/boot/**"
    
            };
    
            // 不拦截的路径
    
            String[] excludePathPatterns = { "/boot/students"
    
            };
    
            // 注册登录拦截器
            registry.addInterceptor(new LoginInterceptor()).addPathPatterns(addPathPatterns)
                    .excludePathPatterns(excludePathPatterns);
    
            // 注册权限拦截器
    
            /*registry.addInterceptor(new AuthInterceptor()).addPathPatterns(addPathPatterns)
                    .excludePathPatterns(excludePathPatterns);*/
    
        }
    }

    LoginInterceptor.java:

    package cn.ted.intercept;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.ModelAndView;
    
    public class LoginInterceptor implements HandlerInterceptor{
    
        public void afterCompletion(HttpServletRequest arg0,
                HttpServletResponse arg1, Object arg2, Exception arg3)
                throws Exception {
            // TODO Auto-generated method stub
            
        }
    
        public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
                Object arg2, ModelAndView arg3) throws Exception {
            // TODO Auto-generated method stub
            
        }
    
        public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,
                Object arg2) throws Exception {
            
            
            System.out.println("进入拦截器");
            return false;
        }
    
    }
    mysql
  • 相关阅读:
    PHP新建文件并写入内容demo
    PHP输出结果demo
    网站顶部图标使用分析
    .htaccess文件的创建 / 联动天下空间伪静态(isapi_rewrite)配置方法
    【原创】网站底部竖线布局对比/研究
    JS判断访问设备终端PC/iPad/iPhone/android 和浏览器IE/Opera/Firefox/webKit
    我的blog风格
    2020.11.17 近日复健情况
    南风又起,锦字题予往昔(写给校刊《我们大多数》)
    【对拍大法好!!】
  • 原文地址:https://www.cnblogs.com/excellent-vb/p/9417907.html
Copyright © 2011-2022 走看看