首页 > 代码库 > softRestTemplate 2
softRestTemplate 2
@SuppressWarnings("unchecked")
public User getUser(String id,String name) {
SoftReference<RestTemplate> softRestTemplate = new SoftReference<RestTemplate>(restTemplate);
String url = null;
HashMap<String, String> uriVariables = new HashMap<String, String>();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
ResponseEntity<User> response=null;
Leaguer body=null;
try {
uriVariables.put("id", id);
uriVariables.put("name", name);
response = softRestTemplate.get().exchange(url,HttpMethod.GET, requestEntity, User.class, uriVariables);
body=response.getBody();
} catch (Exception e) {
e.printStackTrace();
}finally{
softRestTemplate = null;
}
return body;
}