相关文章推荐
销魂的开心果  ·  3、MacBook ...·  1 年前    · 
奔放的生菜  ·  typescript - cdk ...·  2 年前    · 
憨厚的打火机  ·  MPICH vs ...·  2 年前    · 
package com.ftest.springboot.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CrosConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                .allowCredentials(true)
                .allowedHeaders("*")
                .maxAge(3600);

这样就不用担心跨域了!