如何将地图转换为网址查询字符串? [英] How to convert map to url query string?
问题描述
您知道任何可以将Map转换为URL友好查询字符串的实用程序类/库吗?
Do you know of any utility class/library, that can convert Map into URL-friendly query string?
示例:
我有地图:
- param1= 12,
- param2=cat
Example:
I have a map:
- "param1"=12,
- "param2"="cat"
我想要get: param1 = 12& param2 = cat
。
PS。我知道我可以轻松自己编写,我很惊讶我无法在任何地方找到它(我到目前为止检查了Apache Commons)。
PS. I know I can easily write it myself, I am just surprised that I cannot find it anywhere (I checked Apache Commons so far).
推荐答案
我看到的最强大的是 Apache Http Compoments (HttpClient 4.0)的/URLEncodedUtils.htmlrel =noreferrer> URLEncodedUtils )。
The most robust one I saw off-shelf is the URLEncodedUtils class from Apache Http Compoments (HttpClient 4.0).
方法 URLEncodedUtils.format()
是你需要的。
它不使用地图,因此您可以拥有重复的参数名称,例如,
It doesn't use map so you can have duplicate parameter names, like,
a=1&a=2&b=3
不推荐使用这种参数名称。
Not that I recommend this kind of use of parameter names.
这篇关于如何将地图转换为网址查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!