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

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

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

你可能感兴趣的:(springboot拦截请求路径_springboot之路径拦截器)