import org.springframework.context.annotation.Configuration;标签:files,ResourceHandlerRegistry,映射,api,registry,本地,import,图片 From: https://www.cnblogs.com/stevenduxiang/p/18060587
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
*映射本地图片类,找到url对应的文件,配置Spring MVC的一些特性,例如添加静态资源映射
*/
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
/**
* 添加静态资源映射
*
* @param registry ResourceHandlerRegistry实例,用于配置静态资源处理
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// 与设置saveFile.setAvatar_url("http://localhost:8081/api/files" + fileUUID);一致,否则映射不到
registry.addResourceHandler("/api/files/**")
.addResourceLocations("file:G:/duxiang/files/");
registry.addResourceHandler("/api/exercise-show/**")
.addResourceLocations("file:G:/duxiang/exercise-show/");
}
}