准备一个工具类解决前端跨域问题SpringmvcCofing.java
package com.by.config;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Component
public class SpringmvcCofing implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
//**表示所有映射地址
registry.addMapping("/**")
//放行哪些原始域
.allowedOrigins("*")
//允许使用Cookie
.allowCredentials(true)
//允许使用的请求头
.allowedHeaders("*");
}
}