From 44128b40c6dfdc1ccf9014807fa5ce856ea76aaf Mon Sep 17 00:00:00 2001 From: wanggeng <450292408@qq.com> Date: Sat, 7 Aug 2021 11:42:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=B4=E6=97=B6=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cm/common/config/WebConfig.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cloud-common/src/main/java/com/cm/common/config/WebConfig.java b/cloud-common/src/main/java/com/cm/common/config/WebConfig.java index 8136097..1bda5f4 100644 --- a/cloud-common/src/main/java/com/cm/common/config/WebConfig.java +++ b/cloud-common/src/main/java/com/cm/common/config/WebConfig.java @@ -2,11 +2,16 @@ package com.cm.common.config; import com.cm.common.config.properties.FileProperties; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.MultipartConfigFactory; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import javax.servlet.MultipartConfigElement; +import java.io.File; + /** * @ClassName: WebConfig * @Description: Web配置 @@ -30,4 +35,16 @@ public class WebConfig implements WebMvcConfigurer { registry.addResourceHandler("/files/**").addResourceLocations("file:" + fileProperties.getUploadPath()); registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/static/assets/").setCachePeriod(7 * 24 * 3600); } + + @Bean + public MultipartConfigElement multipartConfigElement(){ + MultipartConfigFactory multipartConfigFactory = new MultipartConfigFactory(); + String location = System.getProperty("user.dir") + "/data/tmp"; + File file = new File(location); + if(!file.exists()){ + file.mkdirs(); + } + multipartConfigFactory.setLocation(location); + return multipartConfigFactory.createMultipartConfig(); + } }