2

In the client side, I am using jQuery to submit a number of pairs to the server.

But the number of entries is variable.

For example:

1: 1.55
2: 2.33
3: 5.66

In the server side, how should I design the Controller so that it could take the POST data and store it in a List / Map?

Something like:

@RequestMapping ("/submitdata")
public @ResponseBody String changeData (???) {
// changes to database
return "Success";
}

EDIT:

I got the answer:

@RequestMapping ("/submitdata")
public @ResponseBody String changeData (@RequestParam Map <String, String> params) {

for (Map.Entry<String, String> entry: params.entrySet()) {
            System.out.println ("Key = " + entry.getKey() + " Value = " + entry.getValue());
        }

// changes to database
return "Success";
}
Jeremy
  • 4,797
  • 1
  • 18
  • 26

2 Answers2

0

you can use

@ResponseBody Map<String,String> udpateIdentification(HttpServletResponse response, @ModelAttribute("jspObject") Test test,BindingResult result)

The values will be get bind to the ModelAttribute if you have used that in your JSP

Vins
  • 1,931
  • 16
  • 14
0

You can use @RequestParam annotation to grab POST data

nidhin
  • 6,661
  • 6
  • 32
  • 50