Here you can find the source of buildQuery(final Map
Parameter | Description |
---|---|
query | Map to convert into a text based query |
public static String buildQuery(final Map<String, Object> query)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Map; public class Main { /**/*from w w w. j a v a 2 s.c o m*/ * Turns the specified Map into an encoded & escaped query * * @param query Map to convert into a text based query * @return Resulting query. */ public static String buildQuery(final Map<String, Object> query) { if (query == null) { return ""; } final StringBuilder builder = new StringBuilder(); for (final Map.Entry<String, Object> entry : query.entrySet()) { if (builder.length() > 0) { builder.append('&'); } try { builder.append(URLEncoder.encode(entry.getKey(), "UTF-8")); } catch (final UnsupportedEncodingException e) { } if (entry.getValue() != null) { builder.append('='); try { builder.append(URLEncoder.encode(entry.getValue().toString(), "UTF-8")); } catch (final UnsupportedEncodingException e) { } } } return builder.toString(); } }