You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
995 B
25 lines
995 B
package com.gk.study.config;
|
|
|
|
import com.gk.study.interceptor.AccessInterceptor;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
@Configuration
|
|
public class MyConfig implements WebMvcConfigurer {
|
|
@Override
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
registry.addMapping("/**")//项目中的所有接口都支持跨域
|
|
.allowedOriginPatterns("*") //所有地址都可以访问,也可以配置具体地址
|
|
.allowCredentials(true)
|
|
.allowedMethods("*");//"GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"
|
|
}
|
|
|
|
@Override
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
// 自定义拦截器
|
|
registry.addInterceptor(new AccessInterceptor());
|
|
}
|
|
}
|