web_backend_develope
chenlw 8 years ago
parent 5a7bb65c0b
commit d6a63b0fdf

@ -59,5 +59,16 @@ public class FileOperationTest {
System.out.println(sys.getProperty("os.name"));
}
@Test
public void testsep() {
String sep = "d:\\e\\w\\";
if (sep.endsWith(File.separator)) {
String path = sep.substring(0, sep.length()-1);
System.out.println(path);
}
System.err.println("---");
}
}

@ -15,6 +15,11 @@ public class List2ArrayTest {
s.add(5);
s.add(8);
Integer[] arr =s.toArray(new Integer[s.size()]);
System.out.println(arr);
String str = "";
System.out.println(str.getClass().getName());
String[] strs = new String[20];
System.out.println(strs.getClass().getName());
for (Integer string : arr) {
System.out.println(string);
}

@ -18,5 +18,14 @@ public class MapTest {
CheckoutEntity tmp = map.remove("12");
System.out.println(tmp.getId());
}
@Test
public void testKey() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("/home/gfs_ftp_point/boliang/oracle/320312_97/3-/pengbl_test2/sql_data/320305_34/320312_97/", 2);
map.put("/home/gfs_ftp_point/boliang/oracle/320312_97/3/-/pengbl_test2/sql_data/320305_34/320312_97/", 3);
System.out.println(map.get("/home/gfs_ftp_point/boliang/oracle/320312_97/3-/pengbl_test2/sql_data/320305_34/320312_97/"));
}
}

@ -0,0 +1,31 @@
package com.platform.test;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import com.platform.utils.DateForm;
public class calendarTest {
@Test
public void testOne() {
Calendar c2 = Calendar.getInstance();
System.out.println(DateForm.date2StringBysecond(c2.getTime()));
Map<String, Object> map = new HashMap<String, Object>();
map .put("endTime", DateForm.date2StringBysecond(c2.getTime()));
// 时间设置为 半年前的时间
c2.set(Calendar.DAY_OF_YEAR, c2.get(Calendar.DAY_OF_YEAR) -10);
String time = DateForm.date2StringBysecond(c2.getTime());
System.out.println(time);
// 时间设置为 10天 前的时间
map.put("startTime", time);
for ( String key : map.keySet()) {
System.err.println(key+" "+map.get(key));
}
}
}

@ -0,0 +1,126 @@
package com.platform.test;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.springframework.http.HttpStatus;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.platform.entities.CheckoutEntity;
import com.platform.form.PagerOptions;
import com.platform.http.HttpClientConstant;
import com.platform.http.HttpUtils;
public class httpclientTest {
private static ObjectMapper mapper = new ObjectMapper();
public final static Logger log = Logger.getLogger(HttpUtils.class);
/** post
* @param subUrl
* @param map
* @return
*/
public String sendAjaxPost(String subUrl, String json) {
String resultStr = "";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(subUrl);
try {
// 传参
if (null != json && !"".equals(json)) {
// 建立一个NameValuePair数组用于存储欲传送的参数
StringEntity entity = new StringEntity(json,"UTF-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
post.setEntity(entity);
}
// 发送
HttpResponse respone = client.execute(post);
//接收返回值
if(respone.getStatusLine().getStatusCode() == HttpStatus.OK.value()){
HttpEntity result = respone.getEntity();
if (null != result) {
resultStr = EntityUtils.toString(result);
}
}
} catch (Exception e) {
log.info(HttpClientConstant.URL_IP_PORT + subUrl);
log.error(e);
}
return resultStr;
}
/** post json
* @param subUrl
* @param data
* @return
*/
public String sendAjaxPost(String subUrl, Object data) {
String jsondata = null;
//转成json
if (null != data) {
try {
if (data.getClass().getName().contains("java.util")) {
Writer strWriter = new StringWriter();
mapper.writeValue(strWriter, data);
jsondata = strWriter.toString();
}
else {
Writer strWriter = new StringWriter();
mapper.writeValue(strWriter, data);
jsondata = strWriter.toString();
}
} catch (JsonGenerationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return sendAjaxPost(subUrl, jsondata);
}
public static void main(String[] args) {
httpclientTest ht = new httpclientTest();
PagerOptions p = new PagerOptions();
p.setCurrentPageNum(1);
p.setLimit(20);
p.setVolumeType("1");
System.out.println(ht.sendAjaxPost("http://127.0.0.1:8080/checkout/checkList", p));
List<CheckoutEntity> lis = new ArrayList<CheckoutEntity>();
CheckoutEntity ck = new CheckoutEntity();
ck.setId(2);
ck.setAreaCode("320000");
lis.add(ck);
System.out.println(ht.sendAjaxPost("http://127.0.0.1:8080/checkout/checkList", lis));
}
}
Loading…
Cancel
Save