RestTemplate使用进阶
使用get方式
URI uri = UriComponentsBuilder.fromHttpUrl(t24AchDetailStatusUrl + t24BranchID + T24PathConstants.T24_NY_ACH_DETAIL_STATUS_URL)
.queryParam(Constants.TRACE_NUMBER, traceNumber) //要传的参数
.build()
.toUri();
RequestEntity<Void> requestEntity = RequestEntity
.get(uri)
.header(Constants.APP_ID,appid)
.build();
ResponseEntity<String> response;
response = httpClientTemplate.exchange(requestEntity, String.class);
使用post方式
URI uri = UriComponentsBuilder.fromHttpUrl(ibankEnquiryPreUrl + t24AccountInfoUrl)
.build()
.toUri();
RequestEntity<List<Map<String,String>>> requestEntity = RequestEntity
.post(uri)
.accept(MediaType.APPLICATION_JSON)
.header("Content-Type", "application/json")
.body(accNumsAndBranchNum);
ResponseEntity<String> balanceJson;
balanceJson = restTemplate.exchange(requestEntity, String.class);
使用delete方式
RequestEntity<Void> build = RequestEntity.delete(uri).build();
使用put方式
RequestEntity<Object> body = RequestEntity.put(uri)
.accept(MediaType.APPLICATION_JSON)
.body(new Object());
通过RestTemplate调用URI
ResponseEntity<String> exchange = restTemplate.exchange(requestEntity, String.class);