如何使用spring mvc使用@RequestParam捕获多个参数?

新手上路,请多包涵

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

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

请帮忙!

原文由 Shivayan Mukherjee 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 619
1 个回答
@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。

原文由 Touchstone 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题