zoukankan      html  css  js  c++  java
  • IntelliJ IDEA 2017版 spring-boot搭建拦截器

    1、建立一个springboot-web项目

             https://www.cnblogs.com/liuyangfirst/p/8298588.html

    2、加入过滤接口

     1 public class LoginInterceptor implements HandlerInterceptor {
     2 
     3 
     4     @Override
     5     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
     6 
     7         System.out.println("已经进入了登录拦截器......");
     8 
     9         // 逻辑代码按照之前的方式去编写即可
    10 
    11 
    12         return true;
    13     }
    14 
    15     @Override
    16     public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    17 
    18     }
    19 
    20     @Override
    21     public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
    22 
    23     }
    24 }
    View Code

    3、配置识别类

     1 // 当前类变成配置拦截器类
     2 @Configuration
     3 public class WebConfig extends WebMvcConfigurerAdapter {
     4 
     5     @Override
     6     public void addInterceptors(InterceptorRegistry registry) {
     7 
     8         // 需要拦截的路径
     9         String[] addPathPatterns = {"/test/**"};
    10 
    11         //不拦截的路径
    12         String[] excludePathPatterns = {"/index", "/myjsp"};
    13 
    14 
    15 //        注册登录拦截器(此拦截器注册多行就是,添加多个拦截器)
    16         registry.addInterceptor(new LoginInterceptor())
    17                 .addPathPatterns(addPathPatterns).
    18                 excludePathPatterns(excludePathPatterns);
    19     }
    20 }
    View Code

    4、源码位置

    https://github.com/liushaoye/05-filter/tree/master

  • 相关阅读:
    MINA的session.close
    Maven构建灵活配置文件
    函数的凹凸性
    幂函数习题
    2017全国卷1文科第9题高考真题的解法
    指数函数习题
    三角形的四心的向量表示
    进退中体会数学运算和数学策略
    函数f(x+1)和f(x-1)的奇偶性
    函数的奇偶性周期性习题
  • 原文地址:https://www.cnblogs.com/liuyangfirst/p/9316557.html
Copyright © 2011-2022 走看看