public class RestUtils extends Object
| Constructor and Description |
|---|
RestUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
exchange(org.springframework.web.client.RestTemplate restTemplate,
org.springframework.http.HttpHeaders httpHeaders,
org.springframework.http.MediaType contentType,
URI uri,
org.springframework.http.HttpMethod method,
Object requestBody,
Class<T> responseType)
自定义发送HTTP请求
|
static <T> T |
exchange(org.springframework.web.client.RestTemplate restTemplate,
org.springframework.http.HttpHeaders httpHeaders,
org.springframework.http.MediaType contentType,
URI uri,
org.springframework.http.HttpMethod method,
Object requestBody,
Class<T> responseType,
RestRequestCallback restRequestCallback)
自定义发送HTTP请求
|
static <T> T |
exchange(org.springframework.web.client.RestTemplate restTemplate,
org.springframework.http.MediaType contentType,
String url,
org.springframework.http.HttpMethod method,
Object requestBody,
Class<T> responseType,
Object... uriVariables)
自定义发送HTTP请求
|
static <T> T |
exchange(org.springframework.web.client.RestTemplate restTemplate,
org.springframework.http.MediaType contentType,
URI uri,
org.springframework.http.HttpMethod method,
Object requestBody,
Class<T> responseType)
自定义发送HTTP请求
|
static <T> T |
getForObject(org.springframework.web.client.RestTemplate restTemplate,
String url,
org.springframework.util.LinkedMultiValueMap<String,String> parameterMap,
Class<T> responseType,
Object... uriVariables)
以GET方法发送HTTP请求,并在请求的url中添加动态参数
parameterMap |
static <T> T |
getForObject(org.springframework.web.client.RestTemplate restTemplate,
String url,
Map<String,String> parameterMap,
Class<T> responseType,
Object... uriVariables)
以GET方法发送HTTP请求,并在请求的url中添加动态参数
parameterMap |
static String |
getForString(org.springframework.web.client.RestTemplate restTemplate,
String url,
org.springframework.util.LinkedMultiValueMap<String,String> parameterMap,
Object... uriVariables)
以GET方法发送HTTP请求,并在请求的url中添加动态参数
parameterMap,返回的数据是字符串类型 |
static String |
getForString(org.springframework.web.client.RestTemplate restTemplate,
String url,
Map<String,String> parameterMap,
Object... uriVariables)
以GET方法发送HTTP请求,并在请求的url中添加动态参数
parameterMap,返回的数据是字符串类型 |
static String |
getForString(org.springframework.web.client.RestTemplate restTemplate,
String url,
Object... uriVariables)
以GET方法发送HTTP请求,返回的数据是字符串类型
|
static String |
postForm(org.springframework.web.client.RestTemplate restTemplate,
String url,
org.springframework.util.LinkedMultiValueMap<String,String> requestBody,
Object... uriVariables)
以POST方法发送HTTP请求,请求的内容为form数据格式
|
static String |
postJson(org.springframework.web.client.RestTemplate restTemplate,
String url,
String requestBody,
Object... uriVariables)
以POST方法发送HTTP请求,请求的内容为JSON
|
static org.springframework.web.util.UriComponents |
uriBuild(String url,
Map<String,List<String>> parameterMap,
Object... uriVariables)
构造和编码URI
|
static org.springframework.web.util.UriComponents |
uriBuild2(String url,
Map<String,String> parameterMap,
Object... uriVariables)
构造和编码URI
|
static StringBuilder |
writeForm(Map<String,List<String>> form)
将集合对象转换成 application/x-www-form-urlencoded 表单数据格式
|
static StringBuilder |
writeForm2(Map<String,String> form)
将集合对象转换成 application/x-www-form-urlencoded 表单数据格式
|
public static <T> T exchange(org.springframework.web.client.RestTemplate restTemplate,
org.springframework.http.HttpHeaders httpHeaders,
org.springframework.http.MediaType contentType,
URI uri,
org.springframework.http.HttpMethod method,
Object requestBody,
Class<T> responseType,
RestRequestCallback restRequestCallback)
T - 数据类型class的泛形restTemplate - RestTemplatehttpHeaders - 自定义HttpHeaderscontentType - Internet Media Type,互联网媒体类型uri - 请求的urimethod - 请求方法类型requestBody - 请求的内容responseType - 返回的数据类型restRequestCallback - 回调函数,用于在发送请求之前,做某些处理操作;也可用于在返回结果之前,做某些处理操作public static <T> T exchange(org.springframework.web.client.RestTemplate restTemplate,
org.springframework.http.HttpHeaders httpHeaders,
org.springframework.http.MediaType contentType,
URI uri,
org.springframework.http.HttpMethod method,
Object requestBody,
Class<T> responseType)
T - 数据类型class的泛形restTemplate - RestTemplatehttpHeaders - 自定义HttpHeaderscontentType - Internet Media Type,互联网媒体类型uri - 请求的urimethod - 请求方法类型requestBody - 请求的内容responseType - 返回的数据类型public static <T> T exchange(org.springframework.web.client.RestTemplate restTemplate,
org.springframework.http.MediaType contentType,
URI uri,
org.springframework.http.HttpMethod method,
Object requestBody,
Class<T> responseType)
T - 数据类型class的泛形restTemplate - RestTemplatecontentType - Internet Media Type,互联网媒体类型uri - 请求的urimethod - 请求方法类型requestBody - 请求的内容responseType - 返回的数据类型public static <T> T exchange(org.springframework.web.client.RestTemplate restTemplate,
org.springframework.http.MediaType contentType,
String url,
org.springframework.http.HttpMethod method,
Object requestBody,
Class<T> responseType,
Object... uriVariables)
T - 数据类型class的泛形restTemplate - RestTemplatecontentType - Internet Media Type,互联网媒体类型url - 请求的url,url中可以包含占位符{0}, {1}, {n}method - 请求方法类型requestBody - 请求的内容responseType - 返回的数据类型uriVariables - url中占位符的参数值public static String postJson(org.springframework.web.client.RestTemplate restTemplate, String url, String requestBody, Object... uriVariables)
restTemplate - RestTemplateurl - 请求的url,url中可以包含占位符{0}, {1}, {n}requestBody - 请求的内容uriVariables - url中占位符的参数值public static String postForm(org.springframework.web.client.RestTemplate restTemplate, String url, org.springframework.util.LinkedMultiValueMap<String,String> requestBody, Object... uriVariables)
restTemplate - RestTemplateurl - 请求的url,url中可以包含占位符{0}, {1}, {n}requestBody - 请求的内容uriVariables - url中占位符的参数值public static <T> T getForObject(org.springframework.web.client.RestTemplate restTemplate,
String url,
Map<String,String> parameterMap,
Class<T> responseType,
Object... uriVariables)
parameterMapT - 泛型restTemplate - RestTemplateurl - 请求的url,url中可以包含占位符{0}, {1}, {n}parameterMap - 请求的参数,将会添加到url中responseType - 返回的数据类型uriVariables - url中占位符的参数值public static String getForString(org.springframework.web.client.RestTemplate restTemplate, String url, Map<String,String> parameterMap, Object... uriVariables)
parameterMap,返回的数据是字符串类型restTemplate - RestTemplateurl - 请求的url,url中可以包含占位符{0}, {1}, {n}parameterMap - 请求的参数,将会添加到url中uriVariables - url中占位符的参数值public static String getForString(org.springframework.web.client.RestTemplate restTemplate, String url, Object... uriVariables)
restTemplate - RestTemplateurl - 请求的url,url中可以包含占位符{0}, {1}, {n}uriVariables - url中占位符的参数值public static <T> T getForObject(org.springframework.web.client.RestTemplate restTemplate,
String url,
org.springframework.util.LinkedMultiValueMap<String,String> parameterMap,
Class<T> responseType,
Object... uriVariables)
parameterMapT - 泛型restTemplate - RestTemplateurl - 请求的url,url中可以包含占位符{0}, {1}, {n}parameterMap - 请求的参数,将会添加到url中responseType - 返回的数据类型uriVariables - url中占位符的参数值public static String getForString(org.springframework.web.client.RestTemplate restTemplate, String url, org.springframework.util.LinkedMultiValueMap<String,String> parameterMap, Object... uriVariables)
parameterMap,返回的数据是字符串类型restTemplate - RestTemplateurl - 请求的url,url中可以包含占位符{0}, {1}, {n}parameterMap - 请求的参数,将会添加到url中uriVariables - url中占位符的参数值public static StringBuilder writeForm(Map<String,List<String>> form)
form - FORM表单数据key1=value1&key1=value2&key2=value3public static StringBuilder writeForm2(Map<String,String> form)
form - FORM表单数据key1=value1&key1=value2&key2=value3public static org.springframework.web.util.UriComponents uriBuild(String url, Map<String,List<String>> parameterMap, Object... uriVariables)
url - 原始urlparameterMap - 请求的参数,将会添加到url中uriVariables - uri中占位符的参数值Copyright © 2018. All rights reserved.