zoukankan      html  css  js  c++  java
  • SpringBoot添加拦截器

    自定义拦截器

    package com.company.interceptor;

    import lombok.extern.slf4j.Slf4j;
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.ModelAndView;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    @Slf4j
    public class MyInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    log.debug("preHandle method is running");
    return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    log.debug("postHandle method is running");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
    log.debug("afterCompletion method is running");
    }
    }

    写一个配置类

    package com.company.config;

    import com.company.interceptor.MyInterceptor;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

    @Configuration
    public class MvcConfig implements WebMvcConfigurer{
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
         //指定拦截器类                    //指定拦截路径
    registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");
    }
    }

      

  • 相关阅读:
    声明:此资源由本博客收集整理于网络,只用于交流学习,请勿用作它途。如有侵权,请联系, 删除处理。
    注入点归纳
    网站入侵思路
    关于网上的“人肉”里面的技巧,简单解释
    SQL注入复习
    自己构造注入点方便入侵
    SQL通常注射的一些介绍
    AWVS13破解版安装_Windows
    黑页
    显ipQQ
  • 原文地址:https://www.cnblogs.com/zou-rong/p/12565244.html
Copyright © 2011-2022 走看看