带有飞碟的胸腺和HTML CSS与包装罐一起工作
我有一个带有自定义 CSS 样式的 thymeleaf html 模板和一个“飞碟”来生成 pdf 并从 GET REST 端点下载。
当我运行 Application 类并使用端点时,下载的 pdf 已按预期应用了 css 样式。但是,当它打包在 jar 中并运行时,下载的 pdf 并没有应用样式。
这是 html 模板如何查找 styles.css
<head>
<meta charset="UTF-8"/>
<link th:href="@{src/main/resources/templates/styling.css}" rel="stylesheet" type="text/css"/>
有人能告诉我当应用程序打包在 jar 中时出了什么问题吗?
I have a thymeleaf html template with custom css styling and a 'flying saucer' to produce the pdf and download from the GET REST endpoint.
Here is the project folder structure of the project with template:
When I run the Application class and use the endpoint, the pdf downloaded has the css styling applied as expected. However, when it is packaged in a jar and run, pdf downloaded does not have the styling applied.
And here is how html template looks for styling.css
<head>
<meta charset="UTF-8"/>
<link th:href="@{src/main/resources/templates/styling.css}" rel="stylesheet" type="text/css"/>
Can anybody please tell me what's wrong when applicaion is packged in jar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在胸腺模板中,我对外部CSS的绝对路径如前所述
,当应用为JAR时,通往CSS的路径与不相同。
我尝试使用类似相对路径的尝试
,但这与百里叶的上下文类不起作用,它仅适用于iWebContext类。
因此,作为解决方案,我不得不将Inliner样式添加到模板中,以使其与样式的PDF生成一起使用。
In the thymeleaf template, I had an absolute path for external css as mentioned in
And when application as jar, the path to css is not the same hence it's not resolved.
I tried with relative path like
but this does not work with thymeleaf's Context class, it only works with IWebContext class.
So as a solution, I had to add inliner styles to the template to make it work with styled pdf generation.