From 370c53edfa56f78fc74e246114ee22a8c17de931 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 31 Jul 2021 21:51:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9C=8D=E5=8A=A1=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E8=B5=84=E6=BA=90=E5=85=81=E8=AE=B8=E8=B7=A8=E5=9F=9F?= =?UTF-8?q?=E8=AE=BF=E9=97=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ruoyi/file/config/ResourcesConfig.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/config/ResourcesConfig.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/config/ResourcesConfig.java index 7e44330..3bca668 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/config/ResourcesConfig.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/config/ResourcesConfig.java @@ -3,6 +3,7 @@ package com.ruoyi.file.config; import java.io.File; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -33,4 +34,17 @@ public class ResourcesConfig implements WebMvcConfigurer registry.addResourceHandler(localFilePrefix + "/**") .addResourceLocations("file:" + localFilePath + File.separator); } + + /** + * 开启跨域 + */ + @Override + public void addCorsMappings(CorsRegistry registry) { + // 设置允许跨域的路由 + registry.addMapping(localFilePrefix + "/**") + // 设置允许跨域请求的域名 + .allowedOrigins("*") + // 设置允许的方法 + .allowedMethods("GET"); + } } \ No newline at end of file