本文主要是介绍Spring之RestTemplate如何返回map结果集,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/**
* post请求,然后返回Map结果集
* @param baseUrl
* @param uri
* @param body
* @param <T>
* @return
*/
public <T> Map postForMapResult(String baseUrl, String uri, T body) {Map map = null;try {HttpHeaders httpHeaders = new HttpHeaders();httpHeaders.setContentType(MediaType.APPLICATION_JSON);HttpEntity<T> requestEntity = new HttpEntity<>(body, httpHeaders);ResponseEntity<Map> exchange = restTemplate.exchange(baseUrl + uri, HttpMethod.POST, requestEntity, Map.class);map = exchange.getBody();}catch (RestClientException e){logger.info("postForMapResult异常");}return map;
}
这篇关于Spring之RestTemplate如何返回map结果集的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!