SpringBoot学习笔记(五):SpringBoot中的静态资源的映射规则
发布日期:2021-05-10 07:53:44 浏览次数:15 分类:精选文章

本文共 3682 字,大约阅读时间需要 12 分钟。

���Spring Boot���������������������������������CSS���������������������jQuery���������������������������������������������������������������Spring Boot���������������������������������������������������������������������������������������������������������������������������������������������������������Spring Boot���������������������������������

1. ���������������������������

Spring Boot������������������������������������������������Web������������������������������WebMvcAutoConfiguration������������addResourceHandlers()���������������������������������������������������������

���������������������������������������������������������������������������

  • ������������������������������������������������������������������������������������isAddMappings()������false��������������� statically���������������������������
  • ������������������������������������������ cachePeriod ������������������������������������������������������������������������������������

���������������������������������������������������������������

  • /webjars/****���������������������������JAR������������������������������������jQuery���������
  • /**������������������������������������������������CSS���JavaScript���������

2. ������������������WebJars������

������������Spring���������������������������������������������webapp������������������Spring Boot���������������������������������������������������������������������

������WebJars������������������

WebJars������������������Web������������CSS���JavaScript���������������JAR���������������������Spring Boot������������������WebJars������������������������������������������������������������������

  • ���������������
  • ������WebJars���������������������������������������������������jQuery������
  • ���������������Maven������������������pom.xml������������
    org.webjars
    jquery
    3.4.1
  • 3.������Spring Boot���������������������������JAR���������META-INF/resources/webjars���������������������


3. ������������������������������������

������������������������������������������Spring Boot���������������������������������������������������Spring Boot���������������������������������������

"classpath:/META-INF/resources/""classpath:/resources/""classpath:/static/""classpath:/public/""/:���������������������"

������������������������������������������������"resources"������bootstrap.js������������������������������������http://localhost:8080/resources/bootstrap.js������������


4. ������index.html������

Spring Boot������������index.html������������������������������������������������������������������������������������������������������index.html���������

  • ���������������
  • ������src/main/resources/public���������������������������������������������������index.html������������
  • ������������������������������������������������������
  • ������������������������������������������������������

5. ��������� favicon.ico

Spring Boot������������������������������������������favicon.ico���������������src/main/resources/static/���������������������favicon.ico���

  • ���������������
  • ���������.ico������������������������favicon.ico���������������������src/main/resources/static/������
  • ������Spring Boot������������������������������������������������������������

6. ������������������������������������

���application.properties���������������������������������������������������������������������������������������������������������������������������

# ���������������������������������������������������������������������������������spring.resources.static-locations=classpath:/dir01/,classpath:/dir02/

������������������������������������������������������������������������������������������

上一篇:QT小案例:进制转换与数字提取
下一篇:SpringBoot学习笔记(四):SpringBoot中的日志

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2025年04月15日 06时31分17秒