如何将地图转换为 url 查询字符串?

编程入门 行业动态 更新时间:2024-10-22 17:37:18
本文介绍了如何将地图转换为 url 查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您知道任何可以将 Map 转换为 URL 友好的查询字符串的实用程序类/库吗?

Do you know of any utility class/library, that can convert Map into URL-friendly query string?

示例:

我有一张地图:

"param1"=12, "param2"="cat"

我想得到:

param1=12&param2=cat

最终输出

relativeUrl+param1=12&param2=cat

推荐答案

我看到的最强大的现成方案是 URLEncodedUtils 类来自 Apache Http 组件(HttpClient 4.0).

The most robust one I saw off-the-shelf is the URLEncodedUtils class from Apache Http Compoments (HttpClient 4.0).

URLEncodedUtils.format() 方法正是您所需要的.

The method URLEncodedUtils.format() is what you need.

它不使用 map,所以你可以有重复的参数名称,比如,

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.

更多推荐

如何将地图转换为 url 查询字符串?

本文发布于:2023-11-01 12:34:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549348.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   字符串   如何将   地图   url

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!