31 lines
874 B
Java
31 lines
874 B
Java
package com.guahao;
|
|
|
|
/**
|
|
* @ClassName: UploadConfig
|
|
* @Description:
|
|
* @Author T.W
|
|
* @Date 2021/10/12
|
|
* @Version 1.0
|
|
*/
|
|
|
|
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;
|
|
|
|
/**
|
|
* 设置虚拟路径,访问绝对路径下资源
|
|
*/
|
|
@Configuration
|
|
public class UploadConfig implements WebMvcConfigurer {
|
|
@Value("${file.staticAccessPath}")
|
|
private String staticAccessPath;
|
|
|
|
@Value("${file.uploadFolder}")
|
|
private String uploadFolder;
|
|
@Override
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + uploadFolder);
|
|
}
|
|
}
|