现在都是前后端分离..因为有些时候就会存在跨域问题...跨域可以从前端解决,也可以后端,
贴上后端的代码..
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* 跨域配置
* @author
*
*/
@Configuration
@EnableCaching
public class CorsConfig extends WebMvcConfigurerAdapter{
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "POST")
.maxAge(3600);
}
}