在前后端分离项目中,为了解决使用img标签访问本地图片时产生Not allowed to load local resource的问题,在Spring Boot项目中创建配置类,实现WebMvcConfigurer接口并重写addResourceHandlers方法。
@Configuration
public class MyWebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/foodimg/**").addResourceLocations("file:" +
"/C:/Users/N/Pictures");
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/"); // 没有这句也不起作用
}
}
然而前端使用img标签无法访问图片。
<img class="food-header-img" src="/foodimg/171223.jpg" />
控制台无报错。
请问有人能帮忙解决吗?
或者能帮忙解决Not allowed to load local resource的报错也行,感谢!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…