gpt4 book ai didi

mustache 的 Java Spring 不断在服务器上寻找文件

转载 作者:行者123 更新时间:2023-12-02 10:42:21 37 4
gpt4 key购买 nike

我一直在尝试使用 Java Spring 和 Mustache 进行模板开发一个快速网站,但在获取本地文件(css 样式表或图像)时遇到问题。我正在 IntelliJ 上运行该网站 http://localhost:8000由于某种原因,它会查找 http://localhost:8000/Path/to/the/file 上的每个文件并在检查器上返回 404 错误(控制台日志中没有错误)

这是我的文件树和我正在使用的代码。模板 .mustache 位于 templates 目录中。

filetree

<nav class="level">
<div class="level-left">
<div class="level-item">
<img src="/img/flags/gb.svg"/>
</div>
<div class="level-item">
<img src="/img/flags/fr.svg"/>
</div>
<div class="level-item">
<img src="/img/flags/es.jpg"/>
</div>
<div class="level-item">
<img src="/img/flags/ch.svg"/>
</div>
<div class="level-item">
<img src="/img/flags/de.svg"/>
</div>
</div>
</nav>

我看到一些帖子告诉我们添加这样的资源处理程序:

registry.addResourceHandler("/css/**").addResourceLocations("/resources/static/css");
registry.addResourceHandler("/img/**").addResourceLocations("/resources/static/img");
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/static/");

但到目前为止还没有运气。任何帮助将不胜感激。

最佳答案

尝试将此资源处理程序用于静态资源

registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");

如果它不起作用,您可以在此处进一步检查 - Spring Boot unabe to serve static image from resource folder

关于 mustache 的 Java Spring 不断在服务器上寻找文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52849911/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com