Spring MVC 中的 RequestParam 值不区分大小写
我使用查询字符串将数据从 JSP 发送到控制器。
我的控制器是注释驱动的。
请求参数的值应该不区分大小写。
我用于欢迎页面的方法是
public String welcome(@RequestParam("orgID") String orgID, ModelMap model)
请求参数“orgID”应该不区分大小写。如何做到这一点?
我应该能够将查询字符串指定为“orgid”或“orgId”。该参数应该完全不区分大小写。寻找您的帮助朋友。
提前致谢 :-)
Am sending data from JSP to controller using query string.
My controller is annotation driven.
The value of the the request parameter should be case-insensitive.
The method which i use for welcome page is
public String welcome(@RequestParam("orgID") String orgID, ModelMap model)
The request parameter "orgID" should be case insensitive. How to do this ?.
I should be able to give the query-string as "orgid" or "orgId". The parameter should be completely case-insensitive. Looking for your help friends.
Thanks in Advance :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
另一种方法是有两个参数“orgId”和“orgid”并具有可选参数。
但是,如果您可以控制参数,我强烈希望只采用一种一致的方式,例如 org-id 并在客户端和服务器端都遵循它。
Another approach would be to have two parameters "orgId" and "orgid" and have the optional.
But if you have control over the parameters I would strongly prefer to just have one consistent way, say org-id and follow it both in the client and the server side.
Spring 支持这一点可能会很好,但我也可以理解为什么他们不支持,因为这可能会导致供应商和消费者之间的接口契约减弱。同时,这里有一种相当简单的方法,可以使用参数名称获取第一个值,而不管其大小写。
It might be nice for Spring to support this, but I can also understand why they wouldn't since it could result in a weakening of an interface contract between a supplier and consumer. In the meantime, here's a fairly straightforward way to take the first value using the parameter name regardless of its case.
您必须尝试更改 Spring 匹配您的 url 的方式。首先,您可以创建一个过滤器(可能是 DelegatingFilterProxyBean)来小写您的参数,然后再将其传递给 Spring 或尝试更改路径匹配的方式。
对第二个选项的解释位于 如何在带有带注释的映射的 Spring MVC 中拥有不区分大小写的 URL 。
You'll have to try changing the way Spring matches your urls . You could for one, create a filter (probably a DelegatingFilterProxyBean) to lower case your parameter before you pass it on to Spring or try to change the way the paths are matched .
An explanation to the second options is given at How can I have case insensitive URLS in Spring MVC with annotated mappings .
春季 4.2+
in Spring 4.2+
我发现的最简单的方法是更改控制器方法,以将具有单个键值对的 Map 作为参数,然后将键转换为小写。
The simplest way I found was to change the controller method to take a Map with a single key value pair as a parameter and then convert the key to lowercase.
有一个简单的解决方法。您可以直接操作 HttpServletRequest 并使用方法 getParameter() 并检查参数的所有版本。
There is a simple workaround.You can operate directly on the HttpServletRequest and use method getParameter() and check all versions of parameter.