How to convert map to url query string?

前端 未结 17 1543
盖世英雄少女心
盖世英雄少女心 2020-11-27 13:39

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

Example:

I have a map:

\"param1\"=12,
\"param2         


        
17条回答
  •  爱一瞬间的悲伤
    2020-11-27 14:36

    I found a smooth solution using java 8 and polygenelubricants' solution.

    parameters.entrySet().stream()
        .map(p -> urlEncodeUTF8(p.getKey()) + "=" + urlEncodeUTF8(p.getValue()))
        .reduce((p1, p2) -> p1 + "&" + p2)
        .orElse("");
    

提交回复
热议问题