Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. <form:form id="A" commandName="objectA">
  2. <input type="hidden" name="id" value="1101" />
  3. </form:form>
  4.  
  5. <form:form id="B" commandName="objectB">
  6. <input type="hidden" name="id" value="1102" />
  7. </form:form>
  8.  
  9. <form:form id="C" commandName="objectC">
  10. <input type="hidden" name="id" value="1103" />
  11. </form:form>
  12.  
  13. <form:form id="D" commandName="objectD">
  14. <input type="hidden" name="id" value="1104" />
  15. </form:form>
  16.  
  17. url : "myController/myRequestMapping",
  18. data : $("#A").serialize()+"&"
  19. +$("#B").serialize()+"&"
  20. +$("#C").serialize()+"&"
  21. +$("#D").serialize(),
  22.  
  23. @RequestMapping(value="/myRequestMapping")
  24. public void myFunction(AClass a,BClass b,CClass c,DClass d){
  25. System.out.println("A's ID is:"+a.getId()); //Prints 1101
  26. System.out.println("B's ID is:"+b.getId()); //Prints 1101 instead of 1102
  27. System.out.println("C's ID is:"+c.getId()); //Prints 1101 instead of 1103
  28. System.out.println("D's ID is:"+d.getId()); //Prints 1101 instead of 1104
  29. }
  30.  
  31. public class Form {
  32.  
  33. private Long id;
  34.  
  35. public Form(){}
  36.  
  37. //getters and setters
  38. }
  39.  
  40. public class AllForms extends ArrayList<Form> {}
  41.  
  42. var myarray = [
  43. {id: $('#A').find('input[name="id"]').val()},
  44. {id: $('#B').find('input[name="id"]').val()},
  45. {id: $('#C').find('input[name="id"]').val()},
  46. {id: $('#D').find('input[name="id"]').val()}
  47. ];
  48.  
  49. var jsonStr = JSON.stringify(myarray);
  50.  
  51. url : "myController/myRequestMapping",
  52. data : jsonStr
  53.  
  54. @RequestMapping(value="//myController/myRequestMapping", method=RequestMethod.POST)
  55. public @ResponseBody AllForms process(@RequestBody AllForms allForms){
  56.  
  57. System.out.println(allForms);
  58. return allForms;
  59. }
  60.  
  61. $.post("myController/myRequestMapping",{jsonStr : jsonStr},function(e) {
  62. console.log('success: '+e);
  63. }, "json");
  64.  
  65. @RequestMapping(value="/myController/myRequestMapping", method=RequestMethod.POST)
  66. public @ResponseBody String process(@RequestParam String jsonStr){
  67. System.out.println(jsonStr);
  68.  
  69. //convert here Form instance from jsonStr
  70.  
  71. return jsonStr;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement