From 59e91a4e9ddaf23cebb12993c774aa899ab22d16 Mon Sep 17 00:00:00 2001
From: 郑永安 <zyazyz250@sina.com>
Date: 星期一, 19 六月 2023 14:22:45 +0800
Subject: [PATCH] 描述

---
 src/main/java/com/gk/firework/Config/Cors/MyMvcConfigurer.java |   65 ++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/gk/firework/Config/Cors/MyMvcConfigurer.java b/src/main/java/com/gk/firework/Config/Cors/MyMvcConfigurer.java
new file mode 100644
index 0000000..4b24a51
--- /dev/null
+++ b/src/main/java/com/gk/firework/Config/Cors/MyMvcConfigurer.java
@@ -0,0 +1,65 @@
+package com.gk.firework.Config.Cors;
+
+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;
+
+@Configuration
+public class MyMvcConfigurer implements WebMvcConfigurer {
+    @Value("${filePath}")
+    private String filePath; //配置文件配置的物理保存地址
+    @Value("${sqlPath}")
+    private String sqlPath;
+    @Value("${enterprisePath}")
+    private String enterprisePath; //配置文件配置的物理保存地址
+    @Value("${contractPath}")
+    private String contractPath; //配置文件配置的物理保存地址
+    @Value("${transportCertificatePath}")
+    private String transportCertificatePath;
+    @Value("${hiddenDangerPath}")
+    private String hiddenDangerPath;
+    @Value("${patrolPath}")
+    private String patrolPath;
+    @Value("${appPath}")
+    private String appPath;
+    @Value("${customerPath}")
+    private String customerPath;
+
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        registry.addMapping("/**")
+                .allowedOrigins("*")
+                .allowCredentials(true)
+                .allowedMethods("GET", "POST", "DELETE", "PUT","PATCH")
+                .maxAge(3600);
+    }
+
+    /**服务器静态资源配置**/
+    @Override
+    public void addResourceHandlers(ResourceHandlerRegistry registry) {
+        registry.addResourceHandler("/upload/**")
+                .addResourceLocations("file:"+ filePath)   //媒体资源
+                .addResourceLocations("classpath:/META-INF/resources/"); //swagger2页面
+        registry.addResourceHandler("/dbback/**")
+                .addResourceLocations("file:"+sqlPath);
+        registry.addResourceHandler("/upload/enterprise/**")
+                .addResourceLocations("file:"+enterprisePath);
+        registry.addResourceHandler("/upload/contract/**")
+                .addResourceLocations("file:"+contractPath);
+        registry.addResourceHandler("/upload/transportCertificate/**")
+                .addResourceLocations("file:" + transportCertificatePath);
+        registry.addResourceHandler("/upload/hiddenDanger/**")
+                .addResourceLocations("file:" + hiddenDangerPath);
+        registry.addResourceHandler("/upload/patrol/**")
+                .addResourceLocations("file:" + patrolPath);
+        registry.addResourceHandler("/upload/app/**")
+                .addResourceLocations("file:" + appPath);
+        registry.addResourceHandler("/upload/customer/**")
+                .addResourceLocations("file:" + customerPath);
+        registry.addResourceHandler("/logs/**").
+                addResourceLocations("file:" + System.getProperty("user.dir") + "/logs/");
+
+    }
+}

--
Gitblit v1.9.2