1. html中的img引入的路径没问题,但是在浏览器打开时看不到图片
<img src="/img/cameras.jpg" >
解决:Maven的Lifecycle中选择clean
2. Controller中的RequestMapping中多用了一个前缀,使得静态资源访问的路径总是多加上了这个前缀,不能正确的访问到static下的静态资源
(
Springboot项目可以访问以下目录下的静态资源:
webjars(访问地址 localhost:8080/webjars/…);
classpath下的resources, static(默认) 和 public文件夹(访问地址 localhost:8080/…);
自定义的
)
controller中:
解决:
@Configuration
public class MyMvcConfigurer implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/user/**").addResourceLocations("classpath:/static/");
}
}
参考:https://blog.csdn.net/CatAndBeer/article/details/108460781