WebUtil { public static Map<String,String> queryStringToMap(String queryString,String charset){ try { Map<String,String> map = new HashMap<>(); String[] decode = URLDecoder.decode(queryString,charset).split("&"); for (String keyValue : decode) { String[] kv = keyValue.split("[=]",2); map.put(kv[0],kv.length>1?kv[1]:""); } return map; } catch (UnsupportedEncodingException e) { throw new UnsupportedOperationException(e); } }  static Map<String, String> objectToHttpParameters(Object object); static Map<String,String> queryStringToMap(String queryString,String charset); static HttpServletRequest getHttpServletRequest(); static Map<String, String> getParameters(HttpServletRequest request); static Map<String, String> getHeaders(HttpServletRequest request); static String getIpAddr(HttpServletRequest request); static String getBasePath(HttpServletRequest request);  }
@Test public void queryStringToMap() throws UnsupportedEncodingException { String parameter = "key1=value1&key2=value2&key3=&key4=key5=1"; Map<String, String> map = WebUtil.queryStringToMap(parameter, "utf-8"); System.out.println(map); Assert.assertEquals(map.get("key1"), "value1"); Assert.assertEquals(map.get("key2"), "value2"); Assert.assertEquals(map.get("key3"), ""); Assert.assertEquals(map.get("key4"), "key5=1"); parameter = "key1=%e5%80%bc1&key2=%e5%80%bc2"; map = WebUtil.queryStringToMap(parameter, "utf-8"); System.out.println(map); Assert.assertEquals(map.get("key1"), "值1"); Assert.assertEquals(map.get("key2"), "值2"); parameter = "key1=%D6%B51&key2=%D6%B52"; map = WebUtil.queryStringToMap(parameter, "gbk"); System.out.println(map); Assert.assertEquals(map.get("key1"), "值1"); Assert.assertEquals(map.get("key2"), "值2"); }