为什么要为HREF百里香毛?
我正在部署一个模板,该模板包括弹簧靴,胸腺和引导程序。
为什么模板需要胸腺膜组件?通常,通过从控制器中接收数据,胸腺用于填充索引。但是在这种情况下,胸腺仅在“ href”的前面使用,例如:
[...] th:rel=“stylesheet“ th:href=“@{assets/datatable/datatables.css}"/>
为什么在这种情况下我需要胸腺?如果没有th
-prefixes,是否可以在普通HTML中创建此类引用?真的有必要在这里使用胸腺吗?如果是:为什么?
I am deploying a template that comprises Spring Boot, Thymeleaf and Bootstrap.
Why does the template need the Thymeleaf component? Normally, Thymeleaf is used to populate the index.html-datatable by receiving data from the controller. But in this case, Thymeleaf is only used in front of the „href“, e.g. like:
[...] th:rel=“stylesheet“ th:href=“@{assets/datatable/datatables.css}"/>
Why do I need Thymeleaf in this case? Isn't it possible to create such references in normal HTML just without the th
-prefixes? Is it really necessary to use Thymeleaf here? If yes: Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,可以在没有
th:href
的情况下创建链接。在这种情况下,看起来没有任何理由使用它(因为它是相对链接)。话虽如此,如果链接是上下文相对的(以slash
@{/assets/dataTable/datatables.css}
),使用th:href
让您部署对不同上下文的应用而无需更改链接。如果您不使用th:href
,则必须更改代码才能部署到不同的上下文。例如,如果您决定将应用程序上下文更改为
/my-Online-portal/
之类的内容,则将无法使用。此:
th:href =“@{/Assets/datatable/datatables.css}”
在两种情况下都可以使用,并产生/my-application/assets/datatable/datatable/datatables.css.css 或
/my-online-portal/assets/datatable/datatables.css
取决于部署到的上下文。Yes, it's possible to create links without
th:href
. In this case, doesn't look like there is any reason to use it (since it's a relative link).That being said, if the link was context relative (starting with a slash
@{/assets/datatable/datatables.css}
), usingth:href
would let you deploy the application to different contexts without having to change the link. If you didn't use ath:href
you would have to change the code to deploy to a differnt context. E.g.wouldn't work if you decided to change the application context to something like
/my-online-portal/
.This:
th:href="@{/assets/datatable/datatables.css}"
would work in both cases and produce/my-application/assets/datatable/datatables.css
or/my-online-portal/assets/datatable/datatables.css
depending on the context it's deployed to.