我在模板中有此表。表格单元中有两个按钮
<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