1. 实现HandlerInterceptor;
@Component
public class HttpInterceptor implements HandlerInterceptor {}
2. 添加到拦截器链中;
@Component
public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
private HttpInterceptor httpInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(httpInterceptor);
}
网友评论