我在模板中有此表。表格单元中有两个按钮

<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) {


单击invoice时,我期望:

/*User dashboard:customer clicks re-engage*/
@PostMapping(value="/userdash", params="action=reengage")
public ModelAndView reengage(@RequestParam String recordId, Authentication authentication) {


但是,单击reinvoice按钮时仅执行invoice方法。
单击reengage按钮时re engage方法无法执行

我做错了什么?

最佳答案

//*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

07-24 19:01
查看更多