我刚刚将Bootstrap模板添加到我正在开发的应用程序中,并且正在制作过程中,并且Thymeleaf彼此相似。

当我转到不同的页面时,我无法提供图像-我已经尝试使用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/cssresources/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";


在上面的网址中可以看到的“ 1”是发出的用户ID。

最佳答案

我的猜测是您的图片网址有误。因为您说过将它放在文件夹th:src="@{/img/name.png}"中,它应该不是resources/static/img吗?

10-07 19:33
查看更多