开发者

Spring 3 MVC jQuery POST submit variable number of data

In the client side, I am using jQuery to sub开发者_如何学编程mit 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";
}


You can use @RequestParam annotation to grab POST data


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜