2017-04-11 106 views
0

靜態圖像引用我有一個ApplicationAdvice類,通過每個頁面上引用的資料圖片:傳遞字符串到ApplicationAdvice

@ControllerAdvice 
public class ApplicationAdvice { 
... 

@ModelAttribute("currentProfilePicture") 
    public String currentProfilePicture(Principal principal, Model model) { 

     if (principal != null) { 
      String currentProfilePicture = "@{/images/default-profile-picture.png}"; 
      log.info(currentProfilePicture); 
      model.addAttribute("currentProfilePicture", currentProfilePicture); 
      return currentProfilePicture; 
     } else { 
      String currentProfilePicture = "@{/images/default-profile-picture.png}"; 
      log.info(currentProfilePicture); 
      model.addAttribute("currentProfilePicture", currentProfilePicture); 
      return currentProfilePicture; 
     } 
    } 
} 

HTML:

<img class="profilePicture hvr-pulse-grow" th:src="${currentProfilePicture}" /> 

我不是逃避靜正確引用? @{/images/default-profile-picture.png} URL字符串打印出來罰款...我基本上只是想傳遞一個字符串到一個靜態文件到img標籤。

回答

0

它應該是這樣的:

String currentProfilePicture = "/images/default-profile-picture.png";

<img class="profilePicture hvr-pulse-grow" th:src="@{${currentProfilePicture}}" />

你不可錯過整個thymeleaf串沒有做一些技巧與預處理進行評估,但上述應該做什麼你要。