[英]Thymeleaf static images not being found
我刚刚在我正在处理的应用程序中添加了一个bootstrap模板,并且一直是制作它的过程,而Thymeleaf就像彼此一样。
当我走向不同的页面时,我无法提供图像 - 我已尝试使用th:src="@{/img/name.png}"
表示法和服务器th:src="@{~/img/name.png}"
th:src="@{/img/name.png}"
th:src="@{~/img/name.png}"
我在文档中已经阅读过了。
运行时,应用程序通过以下方式访问: http://localhost:8080/
,没有“应用程序名称”可以说这可能是问题,因为我阅读的一些示例看起来是预期的http://localhost:8080/myApp/myPage.html
。
在此页面上: http://localhost:8080/home
或显示图像的任何其他根级页面。
在其中一个页面上,我将用户重定向到@RequestMapping("/{userid}/users")
,后者解析为http://localhost:8080/1/games
- 在此页面上我遇到了错误。
[Error] Failed to load resource: the server responded with a status of 404 ()
图像为: http://localhost:8080/1/img/icons/double-arrow.png
其中“1”是传递给控制器的userId。
我的css / img文件位于resources/static/css
和resources/static/img
。 我检查并确认它们存在。
我正在使用片段作为页眉和页脚,css和js文件没有问题。
关于如何解决的任何建议都会很棒,谢谢!
编辑以增加一些清晰度:
这是html页面的一部分,
<a href="games.html" th:href="@{/{userid}/users}"/></a>
控制器:
@RequestMapping("/{userid}/users")
public String userGames(@PathVariable final Long userid, Model model){
...get, other methods, etc
return "users";
可以在上面的url中看到的'1'是传入的用户标识。
我的猜测是你的图片网址错了。 不应该是th:src="@{/img/name.png}"
因为你说你把它放在文件夹resources/static/img
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.