xiaoyong931011
2023-10-25 c08844c08e64ad79f25a7e68bbc3f41fea3cded8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cc.mrbird.febs.common.configure;
 
import cc.mrbird.febs.common.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
/**
 * @author xxx
 * @date 2020-08-24
 **/
@Configuration
public class WebMvcConfigure implements WebMvcConfigurer {
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(new LoginInterceptor());
        registration.addPathPatterns("/api/**");
        registration.excludePathPatterns("/api/login/**");
        registration.excludePathPatterns("/api/common/**");
        registration.excludePathPatterns("/api/category/**");
        registration.excludePathPatterns("/api/goods/**");
        registration.excludePathPatterns("/api/pay/**");
        registration.excludePathPatterns("/api/news/**");
        registration.excludePathPatterns("/api/member/cashOutSetting");
        registration.excludePathPatterns("/api/unipay/unipayCallBack");
        registration.excludePathPatterns("/api/unipay/agreeMentPayCallBack");
        registration.excludePathPatterns("/api/unipay/singlePayCallBack");
    }
 
    @Override
    public void addCorsMappings( CorsRegistry registry) {
        registry.addMapping("/**")//允许请求路径
                .allowedOrigins("*")//表示允许所有网址发起跨域请求
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")//表示允许跨域请求的方法
                .maxAge(3600)//表示在3600秒内不需要再发送预校验请求
                .allowCredentials(true);//允许客户端携带验证信息,即允许携带cookie
    }
 
}