R
R
Rocket-API
Search…
自定义拦截器
继承抽象类:com.github.alenfive.rocketapi.extend.ApiInfoInterceptor
1
public class DefaultApiInfoInterceptor extends ApiInfoInterceptor {
2
3
@Override
4
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ApiInfo apiInfo) {
5
return true;
6
}
7
8
@Override
9
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView, ApiInfo apiInfo) {
10
return;
11
}
12
}
Copied!
注册拦截器方式一 ,继承WebMvcConfigurationSupport 会导致默认的资源配置无效,所以需要重新指定
1
@Configuration
2
public class WebSupportConfig extends WebMvcConfigurationSupport {
3
4
@Override
5
public void addResourceHandlers(ResourceHandlerRegistry registry) {
6
registry.addResourceHandler("/rocketapi/**")
7
.addResourceLocations("classpath:/static/rocketapi/");
8
super.addResourceHandlers(registry);
9
}
10
11
@Override
12
public void addInterceptors(InterceptorRegistry registry) {
13
registry.addInterceptor(new DefaultApiInfoInterceptor());
14
}
15
}
Copied!
注册方式二 (推荐)
1
@Configuration
2
public class WebMvcConfig implements WebMvcConfigurer {
3
4
@Override
5
public void addInterceptors(InterceptorRegistry registry) {
6
registry.addInterceptor(new DefaultApiInfoInterceptor());
7
}
8
}
Copied!
Last modified 1yr ago
Copy link