栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot 访问静态资源

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot 访问静态资源

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

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

classpath : --> src/main/resources/

static目录

Spring Boot通过 c l a s s p a t h : / s t a t i c color{red}{classpath : /static } classpath:/static目录访问静态资源。注意存放静态资源的目录名称必须是static。

templates目录

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

SpringBoot 静态资源存放其他位置

c l a s s p a t h : / M E T A − I N F / r e s o u r c e s / color{red}{classpath:/meta - INF/resources/ } classpath:/META−INF/resources/
c l a s s p a t h : / r e s o u r c e s / color{red}{classpath:/resources/} classpath:/resources/
c l a s s p a t h : / s t a t i c color{red}{classpath:/static } classpath:/static
c l a s s p a t h : / p u b l i c / color{red}{classpath:/public/ } classpath:/public/

spring:
	resources:
		static-locations: classpath:/meta-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
自定义 静态资源存放其他位置
spring:
	resources:
		static-locations: classpath:/自定义目录/,[classpath:/meta-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/]		
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/692195.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号