如何使用spring mvc使用@RequestParam捕获多个参数? [英] how to capture multiple parameters using @RequestParam using spring mvc?

查看:49
本文介绍了如何使用spring mvc使用@RequestParam捕获多个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设点击了一个超链接,并使用以下参数列表 myparam=myValue1&myparam=myValue2&myparam=myValue3 触发了一个 url.现在如何在 spring mvc 中使用 @RequestParam 捕获所有参数?

Suppose a hyperlink is clicked and an url is fired with the following parameter list myparam=myValue1&myparam=myValue2&myparam=myValue3 . Now how can I capture all the parameters using @RequestParam in spring mvc?

我的要求是我必须捕获所有参数并将它们放入地图中.

My requirement is I have to capture all the params and put them in a map.

请帮忙!

推荐答案

@RequestMapping(value = "users/newuser", method = RequestMethod.POST)   
public String saveUser(@RequestParam Map<String,String> requestParams) throws Exception{
   String userName=requestParams.get("email");
   String password=requestParams.get("password");

   //perform DB operations

   return "profile";
}

您可以按照上述方式使用 RequestParam.

You could use RequestParam in the above mentioned manner.

这篇关于如何使用spring mvc使用@RequestParam捕获多个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆