2017-09-26 45 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

不起作用.. –

相关问题