首页>代码>基于SpringBoot+Vue实现的学生宿舍管理系统>/最代码/服务端代码/springboot/src/main/java/com/example/springboot/common/CorsConfig.java
package com.example.springboot.common;

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;

@Configuration
public class CorsConfig {

    private CorsConfiguration buildConfig() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*"); // 1容许任何域名使用
        corsConfiguration.addAllowedHeader("*"); // 2容许任何头
        corsConfiguration.addAllowedMethod("*"); // 3容许任何方法(post、get等)
        return corsConfiguration;
    }

    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", buildConfig()); // 4
        return new CorsFilter(source);
    }
}
最近下载更多
微信网友_6786215447367680  LV5 2024年10月11日
yangchengshuai  LV15 2024年9月3日
thsgli  LV9 2024年8月21日
866521  LV2 2024年7月24日
qq970040477  LV24 2024年6月25日
3208941318  LV2 2024年5月14日
792891244  LV3 2024年5月13日
zhanghao943  LV2 2024年4月12日
微信网友_6927932988952576  LV12 2024年3月30日
jc121140  LV3 2024年3月29日
最近浏览更多
xiaohu666 2024年10月22日
暂无贡献等级
黄志琴  LV1 2024年10月19日
微信网友_6786215447367680  LV5 2024年10月11日
Peny_ZH  LV5 2024年9月21日
abdkfksdkf  LV16 2024年9月12日
yangchengshuai  LV15 2024年9月3日
hmf1989 2024年8月23日
暂无贡献等级
thsgli  LV9 2024年8月21日
denliv_hui  LV13 2024年8月19日
chn-lei  LV2 2024年7月31日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友