簡體   English   中英

沒有找到Thymeleaf靜態圖像

[英]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/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'是傳入的用戶標識。

我的猜測是你的圖片網址錯了。 不應該是th:src="@{/img/name.png}"因為你說你把它放在文件夾resources/static/img

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM