thymeleaf - 将 th:each 与 th:href 结合 [英] thymeleaf - combined th:each with th:href

查看:31
本文介绍了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 文档

这篇关于thymeleaf - 将 th:each 与 th:href 结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆