首页>代码>基于SpringBoot+Vue实现的在线考试系统>/OnlineExamSystem/OnlineExamSystemApi/src/main/java/com/rabbiter/oes/config/MvcConfig.java
package com.rabbiter.oes.config; import com.rabbiter.oes.interceptor.LoginInterceptor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class MvcConfig implements WebMvcConfigurer { /** * 配置拦截器 * @param registry 相当于拦截器的注册中心 */ @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new LoginInterceptor()) .addPathPatterns() .excludePathPatterns("/login"); } @Bean public CorsFilter corsFilter() { // 1.创建 CORS 配置对象 CorsConfiguration config = new CorsConfiguration(); // 支持域 config.addAllowedOrigin("*"); // 是否发送 Cookie config.setAllowCredentials(true); // 支持请求方式 config.addAllowedMethod("*"); // 允许的原始请求头部信息 config.addAllowedHeader("*"); // 2.添加地址映射 UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource(); corsConfigurationSource.registerCorsConfiguration("/**", config); // 3.返回 CorsFilter 对象 return new CorsFilter(corsConfigurationSource); } }

coder_f LV2
3月5日
微信网友_7357533879193600 LV2
1月26日
ma406805131 LV19
2024年12月27日
wen435301369 LV17
2024年12月7日
Daima000 LV4
2024年12月3日
citybird LV4
2024年11月18日
wuying8208 LV15
2024年10月23日
withyouatdusk LV2
2024年10月20日
泓鼎168 LV20
2024年5月24日
xuweisong2010 LV28
2024年5月15日