java常用工具库

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
StringUtils.isNotBlank()
StringUtils.isEmpty()

StopWatch watch = new StopWatch();
watch.start();
watch.stop();
watch.getTime();

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
List<Map> commonTags= (List) new Gson().fromJson();
String messageStr= new Gson().toJson(yq);

import java.util.Properties;
Properties properties = new Properties();
properties.put(“bootstrap.servers”, Global.getConfig(“kafka.bootstrap.servers”));

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
List<TestCountry> list = Lists.newArrayList();
Map<String, String> menuMap = Maps.newHashMap();

<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.5</version>
</dependency>
OkHttpClient client = new OkHttpClient();
RequestBody formBody = new FormEncodingBuilder().add(“title”, “测试标题”).add(“context”, “测试内容”)
.build();

Request request = new Request.Builder().url(Global.getConfig(“test.url”)).post(formBody).build();
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
String content = response.body().string();
//content = UnicodeUtils.decodeUnicode(content);
Gson gson = new GsonBuilder().setLenient().enableComplexMapKeySerialization().serializeNulls()
.setPrettyPrinting().disableHtmlEscaping().create();
SplitResult result = gson.fromJson(content, SplitResult.class);
}

<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
HttpClient client = new HttpClient();
client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, “UTF-8”);
client.getHttpConnectionManager().getParams().setConnectionTimeout(2000);
PostMethod method = new PostMethod(url);

NameValuePair[] pairs = new NameValuePair[ map.size()];
int index = 0;
for(String key : map.keySet()){
pairs[index] = new NameValuePair(key, map.get(key));
index++;
}
method.setRequestBody(pairs);
try {
client.executeMethod(method);

System.out.println(“method.getStatusLine()”+method.getStatusLine());
System.out.println(“method.getStatusLine()”+method.getStatusLine());
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

<dependency>
<groupId>commons-dbutils</groupId>
<artifactId>commons-dbutils</artifactId>
<version>1.5</version>
</dependency>
List<Test> list = queryRunner.query(sql, new BeanListHandler<Test>(Test.class));

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.8</version>
</dependency>
HttpHost proxy = new HttpHost(proxyMassge.split(“:”)[0],Integer.valueOf(proxyMassge.split(“:”)[1]));
RequestConfig config = RequestConfig.custom() .setProxy(proxy).build();

HttpGet get = getHttpClient(mainPageUrl);
RequestConfig config = getProxy();
get.setConfig(config);
response = httpclient.execute(get);

Leave a Reply

Your email address will not be published. Required fields are marked *