我有一个 input
字段,其值由 Controller 通过 response.query
设置,在模板中我还有两个执行 read< 的链接
和 delete
对 query
中输入的 id
的调用。这是模板。
<div class="input-group">
<input type="text" th:value="*{response.query}" />
<div class="input-group-btn">
<ul class="dropdown-menu dropdown-menu-right">
<li><a href="#" th:href="@{/read/{id}(id=response.query)}">Read</a></li>
<li><a href="#" th:href="@{/delete/{id}(id=response.query)">Delete</a></li>
</ul>
</div>
</div>
不幸的是,href
参数总是作为null
传递。有替代方法吗?
最佳答案
好吧,让我看看我是否明白你想要什么:
例如,您在文本输入中输入“5”。现在你想 href 到:
http://localhost:8080/read/5
你有一个看起来像这样的 Controller :
@RequestMapping(value="/read/{id}", method=RequestMethod.GET)
public String read(@PathVariable String id, Model model) {
// your logic goes here
return "read";
}
首先我的建议是你可以改变你的代码:
<li><a href="#" th:href="@{/read/{id}(id=response.query)}">Read</a></li>
到:
<li><a href="#" th:href="@{/read/{id}(id=${response.query})}">Read</a></li>
关于javascript - Thymeleaf:将输入文本作为 href 中的参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38692308/