Atitit 命令行dsl传递参数的几种模式对比 cli url模式 键值对NameValuePair urlutil
String string = " -host 10 1 -port 63790 -pwd t 124 -db 1 -smembers 300348232050020352_2019_04_02";
string = " -url http://user1:ttre 2.148.11:63790/1 -get access_token";
string = " -url http://user1:ttre 148.11:63790/1?get=access_token";
看起来貌似url模式更加短小。。。
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.apache.http.Consts;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.helpers.OnlyOnceErrorHandler;
import org.apache.tools.ant.taskdefs.condition.And;
import org.omg.CORBA.NameValuePairHelper;
import org.omg.DynamicAny.NameValuePairSeqHelper;
public class urlParseDemo {
public static void main(String[] args) throws URISyntaxException, ParseException, IOException {
//uri vs url diff ,is uri is Onlystr,And urlAnd Include res op as open
String url = " http://user1:ttre 11:63790/1?get=access_token";
url=url.trim();
URI url2 = new URI(url);
System.out.println(url2.getQuery());
//获取键值对NameValuePair
java.util.List<NameValuePair> list= new URIBuilder(url2).getQueryParams();
System.out.println(list);
//增加键值对
//new URIBuilder().addParameter(param, value)
// 去除键值
//list.remove(o)
//链接为query str模式
//转换为键值对字符串
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(list);
System.out.println( EntityUtils.toString(urlEncodedFormEntity) );
// url2.toURI().get
}