可以在非GET请求上使用@RequestParam吗? [英] Can @RequestParam be used on non GET requests?

查看:602
本文介绍了可以在非GET请求上使用@RequestParam吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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?

这篇关于可以在非GET请求上使用@RequestParam吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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