thymeleaf - 将 th:each 与 th:href 结合起来

2024-01-09

我是 Thymeleaf (和 webdev)的新手,我正在尝试将 Thymeleaf 迭代 (th:each) 与 URL 重写 (th:href) 结合起来。

<a th:each="lid : ${lists}" th:text="${lid}" th:href="@{/list?l=${lid}}">
hello
</a>

这会产生以下结果(其中lid=45):

<a href="/list?l=${lid}">45</a>

因此,它对 th:text 进行了替换,但不对 th:href 进行了替换。

我并没有尝试进行任何形式的 URL 重写,我只是使用“@”语法,因为我希望 Thymeleaf 替换“lid”属性。

我正在使用当前版本的 Thymeleaf (2.1.2) 和 Google App Engine。


如果您不想进行任何 url 重写,则不应使用@ syntax.

您可以使用管道(|) 语法来进行一些文字替换:

th:href="|/list?l=${lid}|"

Source: Thymeleaf 文档 http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#literal-substitutions

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

thymeleaf - 将 th:each 与 th:href 结合起来 的相关文章

随机推荐