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:/METAINF/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/]		
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值