有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

找不到java Thymeleaf静态图像

我刚刚在我正在开发的应用程序中添加了一个引导模板,并且正在制作过程中,Thymeleaf彼此都很喜欢

当我转到不同的页面时,我无法提供图像-我尝试了使用th:src="@{/img/name.png}"符号的上下文和我在文档中通读的服务器th:src="@{~/img/name.png}"

当通过:http://localhost:8080/访问run应用程序时,没有所谓的“应用程序名称”,这可能是问题所在,因为我通读的一些示例看起来是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”是传递给控制器的用户ID

我的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";

在上面的url中可以看到的“1”是传入的用户ID


共 (1) 个答案

  1. # 1 楼答案

    我猜你的图片url是错的。既然你说你把它放在resources/static/img文件夹里,它不应该是th:src="@{/img/name.png}"