新增了上传文件临时目录

This commit is contained in:
wanggeng 2021-08-07 11:42:36 +08:00
parent 124672f4db
commit 44128b40c6

View File

@ -2,11 +2,16 @@ package com.cm.common.config;
import com.cm.common.config.properties.FileProperties; import com.cm.common.config.properties.FileProperties;
import org.springframework.beans.factory.annotation.Autowired; 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.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.servlet.MultipartConfigElement;
import java.io.File;
/** /**
* @ClassName: WebConfig * @ClassName: WebConfig
* @Description: Web配置 * @Description: Web配置
@ -30,4 +35,16 @@ public class WebConfig implements WebMvcConfigurer {
registry.addResourceHandler("/files/**").addResourceLocations("file:" + fileProperties.getUploadPath()); registry.addResourceHandler("/files/**").addResourceLocations("file:" + fileProperties.getUploadPath());
registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/static/assets/").setCachePeriod(7 * 24 * 3600); 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();
}
} }