Springboot访问静态资源

  在Springboot项目中没用我们之前常规的web开发的WebContent(WebApp),它只有src目录

在src/main/resources下面两个文件夹,static和templates。Springboot默认在static目录中存放静态页面,而templates中放动态页面

1,static目录

  Springboot通过classpath/static目录访问静态资源,注意存放静态资源的目录名称必须是static  如:图片 HTML

2,templates目录

  在Springboot中不推荐使用jsp作为视图层技术,而是默认使用Thymeleaf来做动态页面,Templates目录是存放Thymeleaf页面的

3,其他静态资源目录 这里classpath是指main下的resources目录  springboot会按照以下的顺序依次查找静态资源

  classpath:/META-INF/resources/

  classpath:/resources/

  classpath:/static/

  classpath:/public/

4,自定义静态资源目录  如果指定一个自定义目录时 其他的默认静态目录将不会被查找,如果需要多个静态资源目录用逗号隔开可以配置多个

  spring.resources.static-locations=classpath:/suibian/,classpath:/static/

原文地址:https://www.cnblogs.com/yz-bky/p/12759912.html