1.SpringBoot配置静态资源访问与本地路径的映射
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class ApplicationConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
//Windows下
registry.addResourceHandler("/uploads/**").addResourceLocations("file:D:/uploads/");
//Mac或Linux下(没有CDEF盘符)
registry.addResourceHandler("/uploads/**").addResourceLocations("file:/Users/uploads/");
super.addResourceHandlers(registry);
}
}
前端访问URL为localhost:8080/xxx/uploads/**