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;
}

猜你喜欢

转载自blog.csdn.net/u011442726/article/details/107466530