【发布时间】:2016-04-28 15:07:51
【问题描述】:
抱歉标题,不知道如何措辞。我有一个表格,可以在表格中显示一些数据。
<form action="#" th:action="@{/do/stuff}" th:object="${foo}" method="post">
<table>
....
<tr th:each="currentFoo : *{fooList}">
<td>...<td>
<td>
<a th:href="'/anotherPage/' + ${currentFoo.getId()}">
<button>Go to Different page</button>
</a>
</td>
...
</table>
<button type="submit" value="submit">Submit</button>
</form>
然后是控制器:
@RequestMapping(value="/do/stuff", method = RequestMethod.POST)
public String processQuery(@ModelAttribute FooWrapper wrapper, Model model){....}
@RequestMapping(value="anotherPage/{fooID}", method=RequestMethod.GET)
public String getClient(@PathVariable int id, Model model){...}
问题是,当我单击“转到不同页面”按钮时,表单被映射/do/stuff 发布和拾取。
我怎样才能有一个按钮,通过get 传递一个ID,将我带到一个完全不同的页面(将其视为具有编辑条目的选项以及发布所有条目的标准选项)?我只需要到达页面anotherPage/{fooID}
我尝试添加一个按钮表单,希望它会覆盖父表单并对我想要的映射执行get 请求,但它不起作用,这一切都被外部拾取形式。
<form th:action="'/anotherPage/' + ${currentFoo.getID()}" style="display: inline" th:method="get">
<input type="submit" th:value="Go to Page" role="button" />
</form>
这甚至可能吗?如果必须,我什至可以将子方法更改为post,但父表单无法更改。
有什么建议么?
更新 - 我已经找到并发布了一个解决方案,但直到明天我才能接受!
【问题讨论】:
-
是否可以将“转到不同页面”按钮拉到表单外?
-
@ndrone 我不这么认为,因为需要为表格中的每一行动态生成按钮,而且我很确定我不能通过结束表格来“拆分”表格
</table>之前的标签,因为 java spring 不会让你在一个表单中分解<table>...</table>标签(它的全部或全部) - 如果这有意义的话
标签: java spring post spring-boot thymeleaf