Java URL Query Build getQueryString(Map parameters)

Here you can find the source of getQueryString(Map parameters)

Description

get Query String

License

Open Source License

Declaration

public static String getQueryString(Map<String, Object> parameters) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
    public static String getQueryString(Map<String, Object> parameters) {
        if (parameters != null) {
            StringBuilder result = new StringBuilder();
            boolean isFirst = true;
            for (Entry<String, Object> entry : parameters.entrySet()) {
                if (!(entry.getValue() instanceof File)) {
                    if (!isFirst) {
                        result.append("&");
                    }//from www. j ava  2  s. c o m
                    result.append(entry.getKey()).append("=").append(encodeParameter(entry.getValue().toString()));

                    if (isFirst)
                        isFirst = false;
                }
            }
            return result.toString();
        }
        return "";
    }

    public static String encodeParameter(String value) {
        if (value != null) {
            try {
                return URLEncoder.encode(value, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        }
        return "";
    }
}

Related

  1. getQueryParams(String query)
  2. getQueryParams(String s)
  3. getQueryParams(String url)
  4. getQueryString(final Map parameters)
  5. getQueryString(final Map parameters, final boolean encode)
  6. getQueryString(Map parameters)
  7. getQueryString(String url)
  8. getQueryUrl(String word)
  9. getQueryUrl(String word, Integer page)