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

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

问题描述:

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

I'm new to Thymeleaf (and webdev) and I'm trying to combine Thymeleaf iteration (th:each) with URL re-writing (th:href).

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

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

This produces the following (where lid=45):

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

所以,它在 th:text 上做了替换,但不在 th:href 上.

So, it did the substitution on the th:text, but not on the th:href.

我不想做任何类型的 URL 重写,我只是使用@"语法,因为我希望 Thymeleaf 替换lid"属性.

I'm not trying to do any sort of URL re-writing, I'm just using the '@' syntax because I want Thymeleaf to substitute the 'lid' attribute.

我将当前版本的 Thymeleaf (2.1.2) 与 Google App Engine 一起使用.

I'm using the current version of Thymeleaf (2.1.2) with Google App Engine.

如果你不想做任何 url 重写,你不应该使用 @ 语法.

If you don't want to do any url rewriting, you shouldn't use the @ syntax.

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

You can use the pipeline (|) syntax to do some literal substitions:

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

来源:Thymeleaf 文档