在application.yml中定义
#虚拟文件上传路径
upload-path: E:/springBoot/upload/
创建
WebConfigurer类
package com.school.oauth.common.spring;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @Auther: wbh
* @Date: 2019/10/18 17:33
* @Description:
*/
@Configuration
public class WebConfigurer implements WebMvcConfigurer {
@Value("${upload-path}")
private String uploadPath;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("file:"+ uploadPath);
}
}
就可以访问磁盘下的文件了
参考