From a69b31c6d942b816e1e48e9dc017a6f52bd23ae4 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Tue, 31 May 2022 19:04:37 +0800
Subject: [PATCH] 20220527

---
 src/main/java/com/xcong/farmer/cms/configurations/WebMvcConfig.java |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/xcong/farmer/cms/configurations/WebMvcConfig.java b/src/main/java/com/xcong/farmer/cms/configurations/WebMvcConfig.java
index 86faea6..c5c60a5 100644
--- a/src/main/java/com/xcong/farmer/cms/configurations/WebMvcConfig.java
+++ b/src/main/java/com/xcong/farmer/cms/configurations/WebMvcConfig.java
@@ -1,11 +1,16 @@
 package com.xcong.farmer.cms.configurations;
 
+import com.xcong.farmer.cms.common.contants.AppContants;
+import com.xcong.farmer.cms.configurations.properties.ApplicationProperties;
 import com.xcong.farmer.cms.utils.SpringContextHolder;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.SpringBootConfiguration;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
 /**
@@ -37,4 +42,16 @@
     public SpringContextHolder springContextHolder() {
         return new SpringContextHolder();
     }
+
+    @Value("${upload.file.location}")
+    private String fileLocation;
+    @Value("${upload.file.path}")
+    private String filePath;
+    @Override
+    public void addResourceHandlers(ResourceHandlerRegistry registry) {
+        //注册配置类,使用addResourceHandlers方法,将本地路径savePath映射到saveUrl路由上。
+        registry.addResourceHandler(filePath).addResourceLocations(fileLocation);
+        WebMvcConfigurer.super.addResourceHandlers(registry);
+    }
+
 }

--
Gitblit v1.9.1