为 Thymeleaf 变量构造一个 html 锚点,保存绝对 URL(应用程序外部)

MVC*_*man 1 html thymeleaf

我的 Thymeleaf 上下文中有一个变量,称为 r。r 有一个返回 URL 的 getUrl,例如 www.a.co 我想创建一个 HTML 锚点http://www.a.co在 Thymeleaf 中是否有更好的方法?我的解决方案如下,但我不太喜欢它。

<a th:href="@{http://{path}(path=${r.url})}">   
    <span th:text="${r.url}"/> 
</a>
Run Code Online (Sandbox Code Playgroud)

Met*_*ids 5

有很多不同的方法可以做到这一点(取决于您的需要)。我想我更喜欢:

<a th:href="|http://${r.url}|" th:text="${r.url}" /> 
Run Code Online (Sandbox Code Playgroud)

您可能还对其中一项感兴趣:

<a th:href="${'http://' + r.url}" th:text="${r.url}" /> 
<a th:href="'http://' + ${r.url}" th:text="${r.url}" /> 
<a th:href="@{${'http://' + r.url}}" th:text="${r.url}" /> 
Run Code Online (Sandbox Code Playgroud)