注意,前端访问时带上本地服务端的host,例如http://localhost:8080,
后端改写的代码如下,注意file后面一定是三个‘/’,不然的化虽然能解析,但访问不到。
@Configuration
public class LocalPathWebMvcConfigurer extends WebMvcConfigurationSupport {
/**
* 在springboot项目中,允许浏览器访问指定本地文件
*
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/goods-img/**").addResourceLocations("file:///D:/exerciting/java/baajoy-mall-springboot/src/main/resources/goods-img/");
super.addResourceHandlers(registry);
}
}
错误来源https://mp.csdn.net/mp_blog/creation/editor/135489062
错误内容已改正。?