SpringBoot 访问静态资源

SpringBoot 访问静态资源,第1张

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/]		

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5692680.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存