package com.module.interceptor; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @author 轮转 * @date 2022/9/13 * @description */ @Configuration @Slf4j public class WebConfig implements WebMvcConfigurer { @Data class Interceptor implements HandlerInterceptor { private String name; public Interceptor(String name) { this.name = name; } @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { log.info("我是拦截器:" + name); return true; } } @Override public void addInterceptors(InterceptorRegistry registry) { for (int i = 0; i < 10; i++) { registry.addInterceptor(new Interceptor(i + "号")); } } }
标签:拦截器,springboot,springframework,org,import,servlet,public,name From: https://www.cnblogs.com/yyqlz/p/16707156.html