* 将map对象参数转换成String=String&方式
* @param params
* @param charset
* @return
* @throws UnsupportedEncodingException
*/
public static String generateParams(Map<String, String> params,String charset) throws UnsupportedEncodingException{
int flag=0;
StringBuffer ret=new StringBuffer();
Iterator iter = params.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object key = entry.getKey();
Object val = entry.getValue();
if(val!=null){
if(flag==0){
ret.append(key);
ret.append("=");
if(charset!=null&&!charset.equals("")){
ret.append(URLEncoder.encode(val.toString(), charset));
}else{
ret.append(val.toString());
}
flag++;
}else{
ret.append("&");
ret.append(key);
ret.append("=");
if(charset!=null&&!charset.equals("")){
ret.append(URLEncoder.encode(val.toString(), charset));
}else{
ret.append(val.toString());
}
}
}
}
return ret.toString();
}
标签:map,String,val,转换成,charset,ret,toString,append
From: https://blog.51cto.com/u_14682436/6196405