import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import javax.annotation.Resource;
/**
* 功能:过滤请求路径
* @Date 2021/12/31
* @Version 1.0
*/
@Configuration
public class InterceptorAdapterConfig extends WebMvcConfigurerAdapter {
@Resource
private RepeatSubmitInterceptor repeatSubmitInterceptor;
private Logger logger=LoggerFactory.getLogger(InterceptorAdapterConfig.class);
@Override
public void addInterceptors(InterceptorRegistry registry)
{
logger.info("拦截器开始拦截请求路径");
//注册自己的拦截器
//InterceptorRegistration ir = registry.addInterceptor(repeatSubmitInterceptor);
//配置拦截的路径
//registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
//配置不拦截的路径
// registry.addInterceptor(repeatSubmitInterceptor).excludePathPatterns("/helpcenterUserInfo/addUserInfo");
//注册自己的拦截器并设置拦截的请求路径
registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/helpcenterUserInfo/addUserInfo");
}
}
Java拦截器实现代码
于 2022-03-16 15:06:00 首次发布