2017-09-26 50 views
1

我使用Spring Boot,飛碟,百里香葉從html模板創建了一個文件pdf。但圖像不顯示在我的文件中。使用Spring Boot,飛碟和百里香葉在PDF模板中顯示圖像

項目結構:

Project structure

代碼的html:

<div class="col-xs-6 invoice-col-2"> 
    <img src="../static/images/mastercard.png" alt="mastercard"></img> 
</div> 

當我改變img標籤:

<img src="../static/images/mastercard.png" alt="mastercard" th:src="@{static/images/mastercard.png}"></img> 

瓦恩,我創建的PDF文件,我得到一個錯誤:

org.thymeleaf.exceptions.TemplateProcessingException: Link base "static/images/mastercard.png" cannot be context relative (/) or page relative unless you implement the org.thymeleaf.context.IWebContext interface (context is of class: org.thymeleaf.context.Context)

+0

嘗試使用絕對路徑或在'img'tag –

+0

中感謝您的響應,使src =「/ images/mastercard.png」成爲''。我嘗試在img標籤中更改src =「/ images/mastercard.png」,但不顯示圖像。我在img標籤中使用mastercard並顯示。我剛剛做到了。 :)) – dinhbao10t4

回答

0

嘗試使用Spring的classpath:前綴。無論您是從.jar還是在您的IDE中運行,都會直接從類路徑加載文件。下面是一個例子:

<img alt="mastercard" th:src="@{classpath:static/images/mastercard.png}" /> 

更多信息有關classpath:可以在official documentation找到。

+0

不起作用.. –

相關問題