java 跨域请求设置
importorg.springframework.context.annotation.Configuration;importorg.springframework.web.servlet.config.annotation.CorsRegistry;importorg.springframework.web.servlet.config.annotation.WebMvcConfigurer;@ConfigurationpublicclassConfigimplementsWebMvcConfigurer{@OverridepublicvoidaddCorsMappings(CorsRegistry registry){registry.addMapping("/**")// 允许所有路径.allowedOriginPatterns("*")// 允许所有来源(使用 Pattern)// .allowedOrigins("http://localhost:5173") // 允许的前端地址.allowedMethods("GET","POST","PUT","DELETE","OPTIONS")// 允许的方法.allowedHeaders("*")// 允许的请求头.allowCredentials(true)// 允许携带cookie.maxAge(3600);// 预检请求缓存时间(秒)}}