简体   繁体   English

spring3-更改动作方法

[英]spring3 - change the action method

On Spring with annotations, is there anyway that i can change the form action without changing the action using javascript? 在带有注解的Spring上,我是否仍可以在不使用javascript更改动作的情况下更改form动作?

For example on submit1 method invoked on the controller = method1 例如,在控制器= method1上调用的submit1方法上
on submit2 method invoked on the controller = method2 在控制器上调用的commit2方法上= method2

@RequestMapping("/submit1")
public String submit1()

@RequestMapping("/submit2")
public String submit2()

... ...

<form:form id="dynamicfrm" method="post" action="archive/submit.do" commandName="submit">
 <input type="submit1" value="">
 <input type="submit2" value="">

Thank you! 谢谢!

If I understand you correctly - as others already said it isn't absolutely clear - than you want to map one single form to different action methods dependending on the button that was clicked. 如果我正确地理解了您(正如其他人已经说过的那样,还不是很清楚),那么您想根据单击的按钮将一个表单映射到不同的操作方法。

In your JSP you can change the code to something like this: 在您的JSP中,您可以将代码更改为如下所示:

<form action="/submit.do" method="post">
  <input type="submit" name="action" value="show">
  <input type="submit" name="action" value="edit">
</form>

And in your controller you can narrow the mappings like this: 在您的控制器中,您可以像这样缩小映射范围:

@RequestMapping(value = "/submit", params="action=show")
public String showEntity() { /* ... */ }

@RequestMapping(value = "/submit", params="action=edit")
public String editEntity() { /* ... */ }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM