Java专栏 | ||
---|---|---|
上一篇 | 主目录 | 下一篇 |
文章结构
【前言】
本文章系列记录第一次实习中 - - 学习笔记 - - Java的一些问题和解决方式
如何判断Map<String, Object> map中Object是否为""?
public static void main(String[] args) {
Map<String,Object> map=new HashMap<>();
map.put("k","");
System.out.println("k:"+map.get("k").toString());
System.out.println(StringUtils.isNotBlank(map.get("k").toString()));
}
结果:
k:
false
如何读取csv文件,以json格式发送POST请求
public class TestPmml {
public static void testIntelliProductPoints() {
System.out.println("-------------指数模型-------------");
try {
RestTemplate restTemplate =new RestTemplate();
BufferedReader reader = new BufferedReader(new FileReader("XXX.csv"));
reader.readLine();
String line = "3";
while((line=reader.readLine())!=null){String[] strArray = line.split(",");
Map<String, Object> map = new HashMap<String, Object>();
map.put("key1", strArray[7]);
map.put("key2", strArray[8]);
String result = JSONObject.toJSONString(map);
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON_UTF8_VALUE);
HttpEntity<String> httpEntity = new HttpEntity<>(result, headers);
ResponseEntity<String> response = restTemplate.postForEntity("服务器地址\请求", httpEntity, String.class);
if(!response.getStatusCode().equals(HttpStatus.OK)){
//throw new Exception();
}
System.out.println(strArray[0]+"\tscore:"+strArray[28]+"\tprob:"+response.getBody());
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
TestPmml.testIntelliProductPoints();
}
}