小编din*_*0t4的帖子

图像未显示在使用 Spring Boot、飞碟和 Thymeleaf 的 PDF 模板中

我使用 Spring Boot、飞碟、百里香从 html 模板创建了一个文件 pdf。但是图像没有显示在我的文件中。

项目结构:

项目结构

代码html:

<div class="col-xs-6 invoice-col-2">
   <img src="../static/images/mastercard.png" alt="mastercard"></img>
</div>
Run Code Online (Sandbox Code Playgroud)

当我将 img 标签更改为:

<img src="../static/images/mastercard.png" alt="mastercard" th:src="@{static/images/mastercard.png}"></img>
Run Code Online (Sandbox Code Playgroud)

创建 PDF 文件时,出现错误:

org.thymeleaf.exceptions.TemplateProcessingException:链接基“static/images/mastercard.png”不能是上下文相关的(/)或页面相关的,除非你实现了 org.thymeleaf.context.IWebContext 接口(上下文是类:org.thymeleaf .context.Context)

html spring flying-saucer thymeleaf

5
推荐指数
2
解决办法
6091
查看次数

标签 统计

flying-saucer ×1

html ×1

spring ×1

thymeleaf ×1