Java Spring Boot:(六)Spring Boot 访问静态资源

本文介绍了在Spring Boot项目中如何管理和访问静态资源。默认情况下,静态资源存放在`src/main/resources/static`目录,动态页面位于`templates`目录。Spring Boot支持多种路径访问静态资源,包括classpath:/META-INF/resources/, classpath:/resources/, classpath:/static/和classpath:/public/。此外,还讲解了如何自定义静态资源的位置。" 105452837,9427492,SpringData JPA实践:JPQL查询详解,"['Java', 'JPA', 'Hibernate', '数据库开发', 'Spring框架']
摘要由CSDN通过智能技术生成

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

1.static 目录

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

2.templates 目录

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

3.静态资源存放其他位置

  • classpath:/META‐INF/resources/
  • classpath:/resources/
  • classpath:/static/
  • classpath:/public/

4.自定义静态资源位置

spring.resources
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

地球村公民

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值