Thymeleaf - 如何从输入到" href"链接中的参数

时间:2017-07-07 14:05:39

标签: html spring spring-mvc spring-boot thymeleaf

我有这样的输入

<input type="text" id="age" name="age">

并像这样链接

 <a th:href="person?age=????"> GET </a>

我的目标是从输入中获取价值并将其设置为参数&#34;年龄&#34;在href中,因为我有一个弹簧控制器,它捕获一个请求参数。我可以在没有JavaScript的情况下使用,只使用Thymeleaf吗?

1 个答案:

答案 0 :(得分:0)

我不完全确定我理解你想要实现的目标。 Thymeleaf是服务器端模板引擎,因此在将它们发布到服务器之前无法访问本地参数。

如果您尝试使用Thymeleaf从模型(或之前的请求)填充参数,那么这就是语法;

<a th:href="@{person(age=${param.age)}">Link</a>