当前位置:   article > 正文

springboot拦截请求路径_springboot之路径拦截器

springboot security 禁止访问路径

方式一:不推荐,在代码中添加路径

1、写一个拦截器,继承HandlerInterceptor类

importorg.springframework.stereotype.Component;importorg.springframework.web.servlet.HandlerInterceptor;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;

@Componentpublic class ConfigPathInterceptor implementsHandlerInterceptor {

@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throwsException {

System.out.println("执行了拦截器");if(request.getMethod().equalsIgnoreCase("GET")){return true;

}return false;

}

}

2、将拦截器添加至拦截器配置中

importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.InterceptorRegistry;importorg.springframework.web.servlet.config.annotation.WebM

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/716468
推荐阅读
相关标签
  

闽ICP备14008679号