//使用springboot-web组件中的RestTemplate
RestTemplate restTemplate = new RestTemplate();
//getForEntity方法需要用到的参数
Map<String,String> params=new HashMap<>();
params.put("applicationNumber",applicationNumber);
try{
ResponseEntity<ServiceApiResult> result = restTemplate.getForEntity(url+"/v1/api/getBatchTradeList?applicationNumber={applicationNumber}", ServiceApiResult.class, params);
if(result.getBody() != null && result.getBody().getData() != null){
//将字符串类型的数组转换为list集合
JSONArray array = JSONArray.parseArray(JSON.toJSONString(result.getBody().getData()));
List<BatchTradeDtlDto> batchTradeDtlDtos = JSONObject.parseArray(array.toJSONString(),BatchTradeDtlDto.class);
//遍历list集合
for(BatchTradeDtlDto batchTradeDtlDto:batchTradeDtlDtos){
CutPaymentInfo cutPaymentInfo = this.entityToModel(batchTradeDtlDto);
list.add(cutPaymentInfo);
}
}else{
log.info("未获取到数据");
}
}catch(Exception e){
log.error(e.getMessage());
}
Java服务之间直接发送http请求应该怎么做?
猜你喜欢
转载自blog.csdn.net/Genjicoo/article/details/103287034
今日推荐
周排行