【发布时间】:2019-08-31 05:11:24
【问题描述】:
我刚刚向我正在开发的应用程序添加了一个引导模板,并且一直在制作它,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/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'是issue传入的userid。
【问题讨论】:
-
您的图片网址包含“src”但您的静态图片路径不包含?
-
只是为了验证您是否添加了
SecurityConfiguration? -
@soorapadman - 没有安全配置,没有。