@Inject
private RestTemplate restTemplate;
@SuppressWarnings("unchecked")
public User updateUser(User user) {
SoftReference<RestTemplate> softRestTemplate = new SoftReference<RestTemplate>(restTemplate);
String url = null;//请求url
HttpEntity<User> requestEntity = new HttpEntity<User>(user);
ResponseEntity<User> response = null;
User body = null;
try {
response = softRestTemplate.get().postForEntity(url, requestEntity,User.class);
body = response.getBody();
} catch (Exception e) {
e.printStackTrace();
} finally {
softRestTemplate = null;
}
return body;
}
原文地址:http://www.cnblogs.com/yqlwl66/p/3811647.html