实现WebMvcConfigurer接口的addResourceHandlers方法即可
@Configuration
public class FilePathConfig implements WebMvcConfigurer {
@Value("${basePath}")
private String filePath;
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/img/**").addResourceLocations("file:"+filePath);
}
}