1 具体
1.1 参考
详细的资料参考 https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot, 加载静态资源,会从以下几个路径查找:
/META-INF/resources/ /resources/ /static/ /public/
WebMvcAutoConfiguration 源码如下:
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
"classpath:/META-INF/resources/",
"classpath:/resources/",
"classpath:/static/",
"classpath:/public/" };
1.2 建立 static 文件夹
在项目下,建立 static 文件夹。也可以是这个路径 src\main\resources\static。
1.3 建立html文件
建立文件,路径为static\1.html 。 编写内容为 1。
1.4 访问文件