简体   繁体   English

没有找到Thymeleaf静态图像

[英]Thymeleaf static images not being found

I've just added a bootstrap template to the app I'm working on and have been the process of making it, and Thymeleaf like each other. 我刚刚在我正在处理的应用程序中添加了一个bootstrap模板,并且一直是制作它的过程,而Thymeleaf就像彼此一样。

I'm unable to serve up the images when I head off to different pages - I've tried both contextual using the th:src="@{/img/name.png}" notation and the server th:src="@{~/img/name.png}" that I've read through in the docs. 当我走向不同的页面时,我无法提供图像 - 我已尝试使用th:src="@{/img/name.png}"表示法和服务器th:src="@{~/img/name.png}" th:src="@{/img/name.png}" th:src="@{~/img/name.png}"我在文档中已经阅读过了。

When run the application is accessed via : http://localhost:8080/ , there is no 'app name' so to speak which may be the issue as a few of the examples I read through looked to be expected http://localhost:8080/myApp/myPage.html instead. 运行时,应用程序通过以下方式访问: http://localhost:8080/ ,没有“应用程序名称”可以说这可能是问题,因为我阅读的一些示例看起来是预期的http://localhost:8080/myApp/myPage.html

On this page: http://localhost:8080/home or any other root level page the images are displayed. 在此页面上: http://localhost:8080/home或显示图像的任何其他根级页面。

On one of these pages I redirect the user to @RequestMapping("/{userid}/users") which resolves to http://localhost:8080/1/games - it's on this page I encounter the errors. 在其中一个页面上,我将用户重定向到@RequestMapping("/{userid}/users") ,后者解析为http://localhost:8080/1/games - 在此页面上我遇到了错误。

[Error] Failed to load resource: the server responded with a status of 404 () 

With the images being: http://localhost:8080/1/img/icons/double-arrow.png where '1' is the userId that was passed in to the controller. 图像为: http://localhost:8080/1/img/icons/double-arrow.png其中“1”是传递给控制器​​的userId。

My css / img files are in resources/static/css and resources/static/img . 我的css / img文件位于resources/static/cssresources/static/img I've checked and confirmed that they exist. 我检查并确认它们存在。

I'm using fragments for the header and footer, the css and js files don't have a problem. 我正在使用片段作为页眉和页脚,css和js文件没有问题。

Any suggestions on how to resolve would be great, thanks! 关于如何解决的任何建议都会很棒,谢谢!

edited to add some clarity: 编辑以增加一些清晰度:

This is part of the html page, 这是html页面的一部分,

 <a href="games.html" th:href="@{/{userid}/users}"/></a>

the controller: 控制器:

@RequestMapping("/{userid}/users")
    public String userGames(@PathVariable final Long userid, Model model){

...get, other methods, etc
        return "users";

The '1' that can be seen in the url above is the userid that issuing passed in. 可以在上面的url中看到的'1'是传入的用户标识。

My guess is that your image url is wrong. 我的猜测是你的图片网址错了。 Shouldn't it be th:src="@{/img/name.png}" since you said you put it in folder resources/static/img ? 不应该是th:src="@{/img/name.png}"因为你说你把它放在文件夹resources/static/img

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM