Spring Boot 项目中怎么解决跨域问题

需要一个工具类
在这里插入图片描述

package com.kcbg.sportplay.util;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @program: sportplay
 * @description: 解决跨域问题
 * @author: MW
 * @create: 2020-06-15 14:49
 **/
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8080", "null")
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                .maxAge(3600)
                .allowCredentials(true);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_42222342/article/details/106762643