SpringBoot工程配置静态资源访问

在springboot项目中没有我们之前常规web开发的WebContent(WebApp),它只有src目录,在src/main/resources下面有两个文件夹,static和templates。spring boot默认在static目录中存放静态页面,而templates中存放动态页面

static目录

springboot通过classpath/static目录访问静态资源。注意存放静态资源的目录名称必须是static。

templates目录

在spring boot中不推荐使用jsp作为视图层技术,而是默认使用Thymeleaf来做动态页面。Templates目录这是存放基于模板引擎渲染的视图。templates无法直接访问,安全级别比静态目录高,需要通过Controller访问

静态资源存放其他位置

注:访问顺序如下,前面的静态资源不会被后面的覆盖

#properties配置静态资源访问路径
spring.resources.static-locations=classpath:/cs/,classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
#yaml配置静态资源访问路径
spring:
  resources:
    static-locations:
      - classpath:/cs/
      - classpath:/META-INF/resources/
      - classpath:/resources/
      - classpath:/static/
      - classpath:/public/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值