|
@@ -0,0 +1,652 @@
|
|
|
+package cn.com.taiji.transform.util;
|
|
|
+
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @program: RestTemplateUtils
|
|
|
+ * @description: http调用工具类
|
|
|
+ * @author: liwh
|
|
|
+ * @date: 2020/06/09 17:26:00
|
|
|
+ */
|
|
|
+public class RestTemplateUtils {
|
|
|
+
|
|
|
+ private static final RestTemplate restTemplate = new RestTemplate();
|
|
|
+
|
|
|
+ // ----------------------------------GET-------------------------------------------------------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * GET请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> get(String url, Class<T> responseType) {
|
|
|
+ return restTemplate.getForEntity(url, responseType);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * GET请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,按顺序依次对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> get(String url, Class<T> responseType, Object... uriVariables) {
|
|
|
+ return restTemplate.getForEntity(url, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * GET请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,与Map中的key对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> get(String url, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ return restTemplate.getForEntity(url, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 带请求头的GET请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param headers 请求头参数
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,按顺序依次对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> get(String url, Map<String, String> headers, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> get(String url, HttpHeaders headers, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> get(String url, Map<String, String> headers, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> get(String url, HttpHeaders headers, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ HttpEntity<?> requestEntity = new HttpEntity<>(headers);
|
|
|
+ return exchange(url, HttpMethod.GET, requestEntity, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ----------------------------------POST-------------------------------------------------------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * POST请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param formDatas form-data请求参数体
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> postFormData(String url, Map<String,String> formDatas, Class<T> responseType) {
|
|
|
+
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
+
|
|
|
+ MultiValueMap<String, String> formDataMaps= new LinkedMultiValueMap<String, String>();
|
|
|
+
|
|
|
+ for (Map.Entry<String, String> entry : formDatas.entrySet()) {
|
|
|
+
|
|
|
+ String mapKey = entry.getKey();
|
|
|
+ String mapValue = entry.getValue();
|
|
|
+
|
|
|
+ formDataMaps.add(mapKey,mapValue);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ HttpEntity<MultiValueMap<String, String>> requestParams = new HttpEntity<>(formDataMaps, headers);
|
|
|
+
|
|
|
+ return restTemplate.postForEntity(url, requestParams, responseType);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * POST请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> post(String url, Class<T> responseType) {
|
|
|
+ return restTemplate.postForEntity(url, HttpEntity.EMPTY, responseType);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * POST请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param requestBody 请求参数体
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType) {
|
|
|
+ return restTemplate.postForEntity(url, requestBody, responseType);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * POST请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param requestBody 请求参数体
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,按顺序依次对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
|
|
+ return restTemplate.postForEntity(url, requestBody, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * POST请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param requestBody 请求参数体
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,与Map中的key对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> post(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ return restTemplate.postForEntity(url, requestBody, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 带请求头的POST请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param headers 请求头参数
|
|
|
+ * @param requestBody 请求参数体
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,按顺序依次对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> post(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> post(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> post(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> post(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> post(String url, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> post(String url, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ return restTemplate.exchange(url, HttpMethod.POST, requestEntity, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ----------------------------------PUT-------------------------------------------------------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * PUT请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,按顺序依次对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> put(String url, Class<T> responseType, Object... uriVariables) {
|
|
|
+ return put(url, HttpEntity.EMPTY, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * PUT请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param requestBody 请求参数体
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,按顺序依次对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> put(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> put(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> put(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> put(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> put(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> put(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> put(String url, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> put(String url, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ return restTemplate.exchange(url, HttpMethod.PUT, requestEntity, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ----------------------------------DELETE-------------------------------------------------------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * DELETE请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,按顺序依次对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> delete(String url, Class<T> responseType, Object... uriVariables) {
|
|
|
+ return delete(url, HttpEntity.EMPTY, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * DELETE请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,与Map中的key对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> delete(String url, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ return delete(url, HttpEntity.EMPTY, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * DELETE请求调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param requestBody 请求参数体
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,按顺序依次对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> delete(String url, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, Map<String, String> headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, HttpHeaders headers, Object requestBody, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> delete(String url, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ return restTemplate.exchange(url, HttpMethod.DELETE, requestEntity, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ----------------------------------通用方法-------------------------------------------------------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用调用方式
|
|
|
+ *
|
|
|
+ * @param url 请求URL
|
|
|
+ * @param method 请求方法类型
|
|
|
+ * @param requestEntity 请求头和请求体封装对象
|
|
|
+ * @param responseType 返回对象类型
|
|
|
+ * @param uriVariables URL中的变量,按顺序依次对应
|
|
|
+ * @return ResponseEntity 响应对象封装类
|
|
|
+ */
|
|
|
+ public static <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) {
|
|
|
+ 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 static <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables) {
|
|
|
+ return restTemplate.exchange(url, method, requestEntity, responseType, uriVariables);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取RestTemplate实例对象,可自由调用其方法
|
|
|
+ *
|
|
|
+ * @return RestTemplate实例对象
|
|
|
+ */
|
|
|
+ public static RestTemplate getRestTemplate() {
|
|
|
+ return restTemplate;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|