@Test public void testParseQuery() { String query = "id=111&name=test&password=p0ssw0rd"; Map<String, String> queryMap = UrlUtil.parseQuery(query, '&', '=', null); System.out.println(queryMap); Map<String, String> httpQueryMap = UrlUtil.httpParseQuery(query); System.out.println(httpQueryMap); String query2 = "id=111&name=test&password[]=p0ssw0rd&password[]=123456"; Map<String, String> queryMap1 = UrlUtil.parseQuery(query2, '&', '=', ","); System.out.println(queryMap1); Map<String, String> httpQueryMap1 = UrlUtil.httpParseQuery(query2); System.out.println(httpQueryMap1); String query3 = "id=111&name=test&password=p0ssw0rd,123456"; Map<String, String> queryMap2 = UrlUtil.parseQuery(query3, '&', '=', ","); System.out.println(queryMap2); Map<String, String> httpQueryMap2 = UrlUtil.httpParseQuery(query3); System.out.println(httpQueryMap2); }
public static Map<String, String> parseQuery(String query, char split1, char split2, String dupLink) { if (!StringUtil.isEmpty(query) && query.indexOf(split2) > 0) { Map<String, String> result = new HashMap<>(); String name = null; String value = null; String tempValue = ""; int len = query.length(); for (int i = 0; i < len; i++) { char c = query.charAt(i); if (c == split2) { value = ""; } else if (c == split1) { if (!StringUtil.isEmpty(name) && value != null) { if (dupLink != null) { tempValue = result.get(name); if (tempValue != null) { value += dupLink + tempValue; } } result.put(name, value); } name = null; value = null; } else if (value != null) { value += c; } else { name = (name != null) ? (name + c) : "" + c; } } if (!StringUtil.isEmpty(name) && value != null) { if (dupLink != null) { tempValue = result.get(name); if (tempValue != null) { value += dupLink + tempValue; } } result.put(name, value); } return result; } return null; }
UrlUtil { public static Map<String, String> parseQuery(String query, char split1, char split2, String dupLink) { if (!StringUtil.isEmpty(query) && query.indexOf(split2) > 0) { Map<String, String> result = new HashMap<>(); String name = null; String value = null; String tempValue = ""; int len = query.length(); for (int i = 0; i < len; i++) { char c = query.charAt(i); if (c == split2) { value = ""; } else if (c == split1) { if (!StringUtil.isEmpty(name) && value != null) { if (dupLink != null) { tempValue = result.get(name); if (tempValue != null) { value += dupLink + tempValue; } } result.put(name, value); } name = null; value = null; } else if (value != null) { value += c; } else { name = (name != null) ? (name + c) : "" + c; } } if (!StringUtil.isEmpty(name) && value != null) { if (dupLink != null) { tempValue = result.get(name); if (tempValue != null) { value += dupLink + tempValue; } } result.put(name, value); } return result; } return null; } }
UrlUtil { public static Map<String, String> parseQuery(String query, char split1, char split2, String dupLink) { if (!StringUtil.isEmpty(query) && query.indexOf(split2) > 0) { Map<String, String> result = new HashMap<>(); String name = null; String value = null; String tempValue = ""; int len = query.length(); for (int i = 0; i < len; i++) { char c = query.charAt(i); if (c == split2) { value = ""; } else if (c == split1) { if (!StringUtil.isEmpty(name) && value != null) { if (dupLink != null) { tempValue = result.get(name); if (tempValue != null) { value += dupLink + tempValue; } } result.put(name, value); } name = null; value = null; } else if (value != null) { value += c; } else { name = (name != null) ? (name + c) : "" + c; } } if (!StringUtil.isEmpty(name) && value != null) { if (dupLink != null) { tempValue = result.get(name); if (tempValue != null) { value += dupLink + tempValue; } } result.put(name, value); } return result; } return null; }  }
UrlUtil { public static Map<String, String> parseQuery(String query, char split1, char split2, String dupLink) { if (!StringUtil.isEmpty(query) && query.indexOf(split2) > 0) { Map<String, String> result = new HashMap<>(); String name = null; String value = null; String tempValue = ""; int len = query.length(); for (int i = 0; i < len; i++) { char c = query.charAt(i); if (c == split2) { value = ""; } else if (c == split1) { if (!StringUtil.isEmpty(name) && value != null) { if (dupLink != null) { tempValue = result.get(name); if (tempValue != null) { value += dupLink + tempValue; } } result.put(name, value); } name = null; value = null; } else if (value != null) { value += c; } else { name = (name != null) ? (name + c) : "" + c; } } if (!StringUtil.isEmpty(name) && value != null) { if (dupLink != null) { tempValue = result.get(name); if (tempValue != null) { value += dupLink + tempValue; } } result.put(name, value); } return result; } return null; }  static String encodeScheme(String scheme, String encoding); static String encodeScheme(String scheme); static String encodeUserInfo(String userInfo, String encoding); static String encodeUserInfo(String userInfo); static String encodeHost(String host, String encoding); static String encodeHost(String host); static String encodePort(String port, String encoding); static String encodePort(String port); static String encodePath(String path, String encoding); static String encodePath(String path); static String encodePathSegment(String segment, String encoding); static String encodePathSegment(String segment); static String encodeQuery(String query, String encoding); static String encodeQuery(String query); static String encodeQueryParam(String queryParam, String encoding); static String encodeQueryParam(String queryParam); static String encodeFragment(String fragment, String encoding); static String encodeFragment(String fragment); static String encode(String uri); static String encode(String uri, String encoding); static String encodeHttpUrl(String httpUrl); static String encodeHttpUrl(String httpUrl, String encoding); static Builder build(String path); static Builder build(String path, boolean encodePath); static String decode(String url); static String decode(String source, String encoding); static String decodeQuery(String source); static String decodeQuery(String source, String encoding); final static String setParam(String url, String paramName, String paramValue); static final String getParamValue(String url, String paramName); static final String removeParam(String url, String... paramNames); static final String removeParam(String url, String paramName); static String urlJoin(URL url, String locationHeader); static Map print(HttpServletRequest request); static Map<String, String> parseQuery(String query, char split1, char split2, String dupLink); static Map<String, String> httpParseQuery(String queryUri); }
UrlUtil { public static Map<String, String> parseQuery(String query, char split1, char split2, String dupLink) { if (!StringUtil.isEmpty(query) && query.indexOf(split2) > 0) { Map<String, String> result = new HashMap<>(); String name = null; String value = null; String tempValue = ""; int len = query.length(); for (int i = 0; i < len; i++) { char c = query.charAt(i); if (c == split2) { value = ""; } else if (c == split1) { if (!StringUtil.isEmpty(name) && value != null) { if (dupLink != null) { tempValue = result.get(name); if (tempValue != null) { value += dupLink + tempValue; } } result.put(name, value); } name = null; value = null; } else if (value != null) { value += c; } else { name = (name != null) ? (name + c) : "" + c; } } if (!StringUtil.isEmpty(name) && value != null) { if (dupLink != null) { tempValue = result.get(name); if (tempValue != null) { value += dupLink + tempValue; } } result.put(name, value); } return result; } return null; }  static String encodeScheme(String scheme, String encoding); static String encodeScheme(String scheme); static String encodeUserInfo(String userInfo, String encoding); static String encodeUserInfo(String userInfo); static String encodeHost(String host, String encoding); static String encodeHost(String host); static String encodePort(String port, String encoding); static String encodePort(String port); static String encodePath(String path, String encoding); static String encodePath(String path); static String encodePathSegment(String segment, String encoding); static String encodePathSegment(String segment); static String encodeQuery(String query, String encoding); static String encodeQuery(String query); static String encodeQueryParam(String queryParam, String encoding); static String encodeQueryParam(String queryParam); static String encodeFragment(String fragment, String encoding); static String encodeFragment(String fragment); static String encode(String uri); static String encode(String uri, String encoding); static String encodeHttpUrl(String httpUrl); static String encodeHttpUrl(String httpUrl, String encoding); static Builder build(String path); static Builder build(String path, boolean encodePath); static String decode(String url); static String decode(String source, String encoding); static String decodeQuery(String source); static String decodeQuery(String source, String encoding); final static String setParam(String url, String paramName, String paramValue); static final String getParamValue(String url, String paramName); static final String removeParam(String url, String... paramNames); static final String removeParam(String url, String paramName); static String urlJoin(URL url, String locationHeader); static Map print(HttpServletRequest request); static Map<String, String> parseQuery(String query, char split1, char split2, String dupLink); static Map<String, String> httpParseQuery(String queryUri);  }