从一个模块调用另一个模块数据,http请求post连接
public static List<Map<String, Object>> tallyCheck(String str) {//参数一般是经过json转换的字符串
//存储处理过的数据
List<Map<String, Object>> list = null;
try {
Map<String, String> params = new HashMap<>();
//这里的给参数起了一个名字叫“data”放到了连接里
params.put(“data”, str);
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
//设置请求头
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
//调用接口的路径
ResponseEntity result = restTemplate.exchange(comboxUtil.systemConf.getEngineUrl() + “/tallyRuleAutoMatchService/autoMatchCustomData”,
HttpMethod.POST, new HttpEntity(JSON.toJSONString(params), headers), String.class);
//拿到返回值
String resp = result.getBody();
if (StringUtils.isNotEmpty(resp)){
//解析json串
list = JSON.parseObject(resp, new TypeReference<List<Map<String, Object>>>() {});
}
} catch (Exception e) {
logger.error(“tallyCheck error:”,e);
}
return list;
}