Über diese Einstellung springboot virtuelle Verzeichnis, obwohl es eine Menge von Online-verwandten Blog - Tutorials, aber es ist immer noch Blog zu schreiben , es aufzunehmen!
1. Zuerst stellen Sie den Upload - Pfad und statischen Ressourcen - Zugriffspfaddatei in application.yml
#application.yml格式
uploadFile:
path: C:\upload\ #(注意了后面一定加“\”)
staticAccessPath: /upload/**
#application.properties格式
uploadFile.path=C:\upload\
uploadFile.staticAccessPath=/upload/**
2. Klassen-Konfiguration, das virtuelle Verzeichnis Konfiguration schreiben
@Configuration
public class UploadFilePathConfig implements WebMvcConfigurer {
@Value("${uploadFile.path}")
private String uploadFilePath;
@Value("${uploadFile.staticAccessPath}")
private String staticAccessPath;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler(staticAccessPath).addResourceLocations("file:"+uploadFilePath);
}
}
3. Referenz
https://blog.csdn.net/superlover_/article/details/80893007
https://www.cnblogs.com/zuidongfeng/p/8859235.html