RestTemplateUtils工具類,基於Spring框架。

 對Spring的RestTemplate進行封裝,用來執行Http請求。

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * 
 *
 * @author Johny
 * @desc http請求工具類
 */
@Component
public class RestTemplateUtils {

	@Autowired
	private RestTemplate restTemplate;

	// ----------------------------------GET-------------------------------------------------------

	/**
	 * GET請求調用方式
	 *
	 * @param url          請求URL
	 * @param responseType 返回對象類型
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> get(String url, Class<T> responseType) throws RestClientException {
		return restTemplate.getForEntity(url, responseType);
	}

	/**
	 * GET請求調用方式
	 *
	 * @param url          請求URL
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> get(String url, Class<T> responseType, Object... uriVariables)
			throws RestClientException {
		return restTemplate.getForEntity(url, responseType, uriVariables);
	}

	/**
	 * GET請求調用方式
	 *
	 * @param url          請求URL
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> get(String url, Class<T> responseType, Map<String, ?> uriVariables)
			throws RestClientException {
		return restTemplate.getForEntity(url, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的GET請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> get(String url, Map<String, String> headers, Class<T> responseType,
			Object... uriVariables) throws RestClientException {
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.setAll(headers);
		return get(url, httpHeaders, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的GET請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> get(String url, HttpHeaders headers, Class<T> responseType, Object... uriVariables)
			throws RestClientException {
		HttpEntity<?> requestEntity = new HttpEntity<>(headers);
		return exchange(url, HttpMethod.GET, requestEntity, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的GET請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> get(String url, Map<String, String> headers, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.setAll(headers);
		return get(url, httpHeaders, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的GET請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> get(String url, HttpHeaders headers, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		HttpEntity<?> requestEntity = new HttpEntity<>(headers);
		return exchange(url, HttpMethod.GET, requestEntity, responseType, uriVariables);
	}

	// ----------------------------------POST-------------------------------------------------------

	/**
	 * POST請求調用方式
	 *
	 * @param url          請求URL
	 * @param responseType 返回對象類型
	 * @return
	 */
	public <T> ResponseEntity<T> post(String url, Class<T> responseType) throws RestClientException {
		return restTemplate.postForEntity(url, HttpEntity.EMPTY, responseType);
	}

	/**
	 * POST請求調用方式
	 *
	 * @param url          請求URL
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType)
			throws RestClientException {
		return restTemplate.postForEntity(url, requestBody, responseType);
	}

	/**
	 * POST請求調用方式
	 *
	 * @param url          請求URL
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Object... uriVariables)
			throws RestClientException {
		return restTemplate.postForEntity(url, requestBody, responseType, uriVariables);
	}

	/**
	 * POST請求調用方式
	 *
	 * @param url          請求URL
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		return restTemplate.postForEntity(url, requestBody, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的POST請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> post(String url, Map<String, String> headers, Object requestBody,
			Class<T> responseType, Object... uriVariables) throws RestClientException {
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.setAll(headers);
		return post(url, httpHeaders, requestBody, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的POST請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> post(String url, HttpHeaders headers, Object requestBody, Class<T> responseType,
			Object... uriVariables) throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
		return post(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的POST請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> post(String url, Map<String, String> headers, Object requestBody,
			Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.setAll(headers);
		return post(url, httpHeaders, requestBody, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的POST請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> post(String url, HttpHeaders headers, Object requestBody, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
		return post(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * 自定義請求頭和請求體的POST請求調用方式
	 *
	 * @param url           請求URL
	 * @param requestEntity 請求頭和請求體封裝對象
	 * @param responseType  返回對象類型
	 * @param uriVariables  URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> post(String url, HttpEntity<?> requestEntity, Class<T> responseType,
			Object... uriVariables) throws RestClientException {
		return restTemplate.exchange(url, HttpMethod.POST, requestEntity, responseType, uriVariables);
	}

	/**
	 * 自定義請求頭和請求體的POST請求調用方式
	 *
	 * @param url           請求URL
	 * @param requestEntity 請求頭和請求體封裝對象
	 * @param responseType  返回對象類型
	 * @param uriVariables  URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> post(String url, HttpEntity<?> requestEntity, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		return restTemplate.exchange(url, HttpMethod.POST, requestEntity, responseType, uriVariables);
	}

	// ----------------------------------PUT-------------------------------------------------------

	/**
	 * PUT請求調用方式
	 *
	 * @param url          請求URL
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> put(String url, Class<T> responseType, Object... uriVariables)
			throws RestClientException {
		return put(url, HttpEntity.EMPTY, responseType, uriVariables);
	}

	/**
	 * PUT請求調用方式
	 *
	 * @param url          請求URL
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> put(String url, Object requestBody, Class<T> responseType, Object... uriVariables)
			throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
		return put(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * PUT請求調用方式
	 *
	 * @param url          請求URL
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> put(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables)
			throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
		return put(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的PUT請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> put(String url, Map<String, String> headers, Object requestBody, Class<T> responseType,
			Object... uriVariables) throws RestClientException {
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.setAll(headers);
		return put(url, httpHeaders, requestBody, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的PUT請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> put(String url, HttpHeaders headers, Object requestBody, Class<T> responseType,
			Object... uriVariables) throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
		return put(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的PUT請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> put(String url, Map<String, String> headers, Object requestBody, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.setAll(headers);
		return put(url, httpHeaders, requestBody, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的PUT請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> put(String url, HttpHeaders headers, Object requestBody, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
		return put(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * 自定義請求頭和請求體的PUT請求調用方式
	 *
	 * @param url           請求URL
	 * @param requestEntity 請求頭和請求體封裝對象
	 * @param responseType  返回對象類型
	 * @param uriVariables  URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> put(String url, HttpEntity<?> requestEntity, Class<T> responseType,
			Object... uriVariables) throws RestClientException {
		return restTemplate.exchange(url, HttpMethod.PUT, requestEntity, responseType, uriVariables);
	}

	/**
	 * 自定義請求頭和請求體的PUT請求調用方式
	 *
	 * @param url           請求URL
	 * @param requestEntity 請求頭和請求體封裝對象
	 * @param responseType  返回對象類型
	 * @param uriVariables  URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> put(String url, HttpEntity<?> requestEntity, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		return restTemplate.exchange(url, HttpMethod.PUT, requestEntity, responseType, uriVariables);
	}

	// ----------------------------------DELETE-------------------------------------------------------

	/**
	 * DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, Class<T> responseType, Object... uriVariables)
			throws RestClientException {
		return delete(url, HttpEntity.EMPTY, responseType, uriVariables);
	}

	/**
	 * DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, Class<T> responseType, Map<String, ?> uriVariables)
			throws RestClientException {
		return delete(url, HttpEntity.EMPTY, responseType, uriVariables);
	}

	/**
	 * DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, Object requestBody, Class<T> responseType, Object... uriVariables)
			throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
		return delete(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, Object requestBody, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody);
		return delete(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Class<T> responseType,
			Object... uriVariables) throws RestClientException {
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.setAll(headers);
		return delete(url, httpHeaders, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Class<T> responseType, Object... uriVariables)
			throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(headers);
		return delete(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.setAll(headers);
		return delete(url, httpHeaders, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(headers);
		return delete(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Object requestBody,
			Class<T> responseType, Object... uriVariables) throws RestClientException {
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.setAll(headers);
		return delete(url, httpHeaders, requestBody, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Object requestBody, Class<T> responseType,
			Object... uriVariables) throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
		return delete(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Object requestBody,
			Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
		HttpHeaders httpHeaders = new HttpHeaders();
		httpHeaders.setAll(headers);
		return delete(url, httpHeaders, requestBody, responseType, uriVariables);
	}

	/**
	 * 帶請求頭的DELETE請求調用方式
	 *
	 * @param url          請求URL
	 * @param headers      請求頭參數
	 * @param requestBody  請求參數體
	 * @param responseType 返回對象類型
	 * @param uriVariables URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Object requestBody, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		HttpEntity<Object> requestEntity = new HttpEntity<Object>(requestBody, headers);
		return delete(url, requestEntity, responseType, uriVariables);
	}

	/**
	 * 自定義請求頭和請求體的DELETE請求調用方式
	 *
	 * @param url           請求URL
	 * @param requestEntity 請求頭和請求體封裝對象
	 * @param responseType  返回對象類型
	 * @param uriVariables  URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, HttpEntity<?> requestEntity, Class<T> responseType,
			Object... uriVariables) throws RestClientException {
		return restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, responseType, uriVariables);
	}

	/**
	 * 自定義請求頭和請求體的DELETE請求調用方式
	 *
	 * @param url           請求URL
	 * @param requestEntity 請求頭和請求體封裝對象
	 * @param responseType  返回對象類型
	 * @param uriVariables  URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> delete(String url, HttpEntity<?> requestEntity, Class<T> responseType,
			Map<String, ?> uriVariables) throws RestClientException {
		return restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, responseType, uriVariables);
	}

	// ----------------------------------通用方法-------------------------------------------------------

	/**
	 * 通用調用方式
	 *
	 * @param url           請求URL
	 * @param method        請求方法類型
	 * @param requestEntity 請求頭和請求體封裝對象
	 * @param responseType  返回對象類型
	 * @param uriVariables  URL中的變量,按順序依次對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
			Class<T> responseType, Object... uriVariables) throws RestClientException {
		return restTemplate.exchange(url, method, requestEntity, responseType, uriVariables);
	}

	/**
	 * 通用調用方式
	 *
	 * @param url           請求URL
	 * @param method        請求方法類型
	 * @param requestEntity 請求頭和請求體封裝對象
	 * @param responseType  返回對象類型
	 * @param uriVariables  URL中的變量,與Map中的key對應
	 * @return ResponseEntity 響應對象封裝類
	 */
	public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
			Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
		return restTemplate.exchange(url, method, requestEntity, responseType, uriVariables);
	}

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章