究竟什么是@RequestParam以及它是如何填充的? [英] What exactly is @RequestParam and how does it get populated?

查看:445
本文介绍了究竟什么是@RequestParam以及它是如何填充的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring文档说:

Spring documentation says:


使用@RequestParam注释将请求参数绑定到控制器中的
方法参数。

Use the @RequestParam annotation to bind request parameters to a method parameter in your controller.

来源:
http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc。 html#mvc-ann-requestparam

AFAIK,请求参数是在请求方法为GET时从查询字符串中检索的变量。它们也是请求方法POST时从表单值检索的变量。我已经使用一个简单的JSP验证了这一点,该JSP通过方法request.getParameter(key)显示请求参数。

AFAIK, request parameters are variables retrieved from query strings if the request method is GET. They are also the variables retrieved from the form values when the request method is POST. I've verified this using a simple JSP that displays request parameters through method request.getParameter("key").

但在我看来@RequestParam仅适用于GET方法请求。它只能从查询字符串中获取值。

But it seems to me that @RequestParam only works on GET method requests. It can only get values from query strings.

这是文档中的错误吗?有人可以引用一些文档来描述@RequestParam用于什么,它不能用于什么,以及如何填充它?

Is this a bug in the documentation? Can someone please cite me some documentation that describes exactly what @RequestParam is used for, what it cannot be used for, and how it gets populated?

我可以使用@RequestParam吗? POST方法获取表单值?如果我不能使用@RequestParam,我还能使用什么?我试图避免调用request.getParameter(key)。

Can I use @RequestParam for POST methods to get the form values? If I can't use @RequestParam, what else can I use? I'm trying to avoid calling request.getParameter("key").

推荐答案

它也适用于帖子。你可以发布你的方法体和你的HTML吗?

It works with posts too. Can you post your method body and you html?

这篇关于究竟什么是@RequestParam以及它是如何填充的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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