带有变量的百里香绝对 URL [英] thymeleaf absolute URL with variable
问题描述
我正在尝试使用 Thymeleaf 将域 url 注入到链接中.我的 url 是从控制器传递过来的,因为我记录了日志并看到了它.
I am trying to inject a domain url into a link using Thymeleaf. My url is being passed from the controller because i put logging and saw it.
我的链接在我的 Thymeleaf html 模板中是这样的:
my link is as such in my Thymeleaf html template:
<link type="text/css" th:href="@{${DomainUrl}/web/assets/css/foundation5/foundation.min.css}" rel="stylesheet" />
但是,当我在本地运行它时,它不会替换域,例如,抛出一个错误(因为当然找不到 URL)渲染如下:http://localhost:8081/pss/ui/$%7BDomainUrl%7D/web/assets/css/components.css
however, when I run it locally it doesn't replace the domain, for example, throws an error (because the URL is not found of course) render as such: http://localhost:8081/pss/ui/$%7BDomainUrl%7D/web/assets/css/components.css
推荐答案
好吧,为了让它起作用,你必须使用预处理运算符 __expression__
来获取属性链接,这样你最终会得到一些想法这个
Ok so in order for this to work you must use preprocess operator __expression__
to get propert link so you will end up with somethink like this
<link type="text/css" th:href="@{__${DomainUrl}__/web/assets/css/foundation5/foundation.min.css}" rel="stylesheet" />
这将预处理和解析 ${DomainUrl}
表达式,并将结果字符串传递给 @
表达式处理器.经过测试和工作的魅力:
this will preprocess and resolve ${DomainUrl}
expression, and will pass resulting string to to @
expression processor. Tested and work like charm:
<a th:href="@{__${currentUrl}__/blah/blah/blahhhh}">hey there</a>
生成
<a href="http://localhost:8080/admin/place/list/blah/blah/blahhhh">hey there</a>
其中 http://localhost:8080/admin/place/list/
是 currentUrl
在我的
这篇关于带有变量的百里香绝对 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!