在thymeleaf中图像的相对路径

e4eetjau  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(522)

我要呈现pdf从thymeleaf模板。我在为存储在中的图像指定路径时遇到一些问题 resources/static/images/writing.png ```

如果我在web浏览器中打开页面,上面的代码工作得很好,但当我尝试使用templateengine处理它时,它会引发异常

Link base "/images/writing.png" cannot be context relative (/...) unless the context used for executing the engine implements the org.thymeleaf.context.IWebContext interface (template: "TimetablePDF" - line 64, col 26)

我可以选择在src中指定完整路径,比如 `http://localhost/images/...` 但我觉得很糟糕,我不想那样做。
那么我如何在没有硬编码的情况下指定它呢?
fquxozlt

fquxozlt1#

这对我有用

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

相关问题