遍历格式 XXX=123&XXX=456.....参数为map
treemap是一个有序的key-value集合,它是通过红黑树实现的
TreeMap<String, String> treeMap = new TreeMap<>();
for (Map.Entry<String, String> entry : map.entrySet()) {
if ("signature".equals(entry.getKey().trim())) {
continue;
}
if (StringUtils.isBlank(entry.getValue())) {
continue;
}
treeMap.put(entry.getKey(), entry.getValue());
}
StringBuilder stringBuilder = new StringBuilder();
for (Map.Entry<String, String> entry : treeMap.entrySet()) {
stringBuilder.append(entry.getKey());
stringBuilder.append("=");
stringBuilder.append(entry.getValue());
stringBuilder.append("&");
}
String result = "";
if (StringUtils.isNotBlank(stringBuilder.toString())) {
result = stringBuilder.substring(0, stringBuilder.length() - 1);
}
return result;
}