gpt4 book ai didi

java - Spring Boot资源静态文件夹

转载 作者:行者123 更新时间:2023-12-02 03:04:56 25 4
gpt4 key购买 nike

不久,我的应用程序的结构如下,问题是 Spring Boot 不递归扫描静态文件夹。我是说如果我将 bootstrap.min.css 放入 static/css/bootstrap.min.css没关系,没问题,但如果我放入静态文件夹 static/bootstrap/bootstrap.min.css 子包中的另一个文件夹中,就像屏幕截图中一样,我无法加载这些资源。我该如何处理这个问题?提前致谢。 enter image description here

最佳答案

您的网址缺少前导斜杠。

http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#link-urls

There are different types of URLs:

  • Absolute URLs: http://www.thymeleaf.org
  • Relative URLs, which can be:
    • Page-relative: user/login.html
    • Context-relative: /itemdetails?id=3 (context name in server will be added automatically)
    • Server-relative: ~/billing/processInvoice (allows calling URLs in another context (= application) in the same server.
    • Protocol-relative URLs: //code.jquery.com/jquery-2.0.3.min.js

屏幕截图中的 URL bootstrap/css/bootstrap.min.css 是相对于页面的。

您需要的是一个上下文相关的 URL。当您的文件位于 src/main/resources/static/css/bootstrap.min.css 中时,请使用:

th:href="@{/css/bootstrap.min.css}"

当它位于src/main/resources/static/bootstrap/bootstrap.min.css中时,使用:

th:href="@{/bootstrap/bootstrap.min.css}"

此外,我建议您使用Bootstrap WebJar,而不是手动下载bootstrap.min.css。然后使用以下href:

th:href="@{/webjars/bootstrap/3.3.6/css/bootstrap.min.css}"

关于java - Spring Boot资源静态文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41881232/

25 4 0
文章推荐: java - 如何对 Stream 的某些部分执行归约操作
文章推荐: java - 基于box2D body 角度旋转textureRegion(无 Sprite )
文章推荐: java - build.properties 在 puppet 中等效吗?
文章推荐: java - 流: cannot convert from Stream的流