我在模板中有这张表。表格单元格中有两个按钮
<td>
<form action="#" data-th-action="@{/userdash}" method="POST">
<input type="hidden" name="id" th:value="${acc.recordId}" />
<button type="submit" name="action" value="reengage">Re Engage</button>
<button type="submit" name="action" value="reinvoice">invoice</button>
</form>
当点击Re Engage
时,我预计会触发以下内容。:
/*User dashboard:customer clicks invoice*/
@PostMapping(value="/userdash", params="action=reinvoice")
public ModelAndView reinvoice(@RequestParam String id,Authentication authentication) {
当点击发票
时,我期望:
/*User dashboard:customer clicks re-engage*/
@PostMapping(value="/userdash", params="action=reengage")
public ModelAndView reengage(@RequestParam String recordId, Authentication authentication) {
但是当点击invoice
按钮时,只会执行reinvoice
方法。
单击reengage
按钮时,reengage
方法无法执行
我做错了什么?
最佳答案
//*User dashboard:customer clicks re-engage*/
@PostMapping(value="/userdash", params="action=reengage")
public ModelAndView reengage(@RequestParam String recordId, Authentication
authentication) {
将 rocordId
更改为 id
并尝试。如下所示:
/*User dashboard:customer clicks re-engage*/
@PostMapping(value="/userdash", params="action=reengage")
public ModelAndView reengage(@RequestParam String id, Authentication
authentication) {
上面代码中的问题是 requestParam 需要 recordId
并且您将 param 作为 id
传递
关于java - Spring Controller 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49771809/