- main
- resources
- public
- resources
- static
- resources
- static
- public
根据 SpringBoot 源代码可以得出结论
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/" };
springboot的配置类为 : WebMvcAutoConfiguration
- public
- 公共调用的 js、css 文件 (jQuery、Bootstrap)
- static
- 静态资源 图片等资源
- resources
- 上传的文件等 (如图片、文档等文件内容
private Resource getIndexHtml(String location) {
return this.resourceLoader.getResource(location + "index.html");
}
// location 的值
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/",
"classpath:/resources/", "classpath:/static/", "classpath:/public/" };
欢迎页面index.html合法存在的位置,如 js,css 等静态资源所在位置相同
- static 文件夹
- public 文件夹
- resources 文件夹
暂且定义到static文件夹下面,来存放网站的首页与静态资源的配置
|-resources
? |-static
? |-index.html √可以访问 (符合源码路径的描述)
? |-public
? |-index.html √可以访问 (符合源码路径的描述)
? |-resources
? |-index.html √可以访问 (符合源码路径的描述)
? |-templates
? |-index.html √可以访问 (需要控制器的配合调用)
? |-index.html ×不可以访问 (不符合源码路径的描述)
resources根目录下不可以放置index.html首页文件,因为源码中没有指定路径的权限,但是可以自己配置权限路径(虽然不推荐这么做)
值得注意的是
templates 文件夹下的页面文件,必须要走控制器才可以到达,然而这种方法确实springboot的标准写法,或是常用写法,因为在实际开发的过程中,难免会有许多的页面需要处理,如果放在三大静态资源文件夹下来进行处理,会导致结构线条紊乱,所以将所有的HTML页面,放到templates页面下,通过控制器来进行管理是最明智的选择
首页图标的定制在版本 2.2.7 以上会移除源码,2.1.x 可以设置网站图标
设置方式
根据源码可以得出结论,在类路径下的 resources 文件夹下新建一张图片,命名为favicon.ico
文件夹结构
resources
? |--……
? |--favicon.ico
原文:https://www.cnblogs.com/JQ04/p/13734620.html