Java中的RestTemplate-RestTemplate没有足够的可用变量值
我有以下几点:Java中的RestTemplate-RestTemplate没有足够的可用变量值,java,spring,spring-mvc,url,resttemplate,Java,Spring,Spring Mvc,Url,Resttemplate,我有以下几点: final String notification = "{\"DATA\"}"; final String url = "http://{DATA}/create"; ResponseEntity<String> auth = create(address, name, psswd, url); 为什么?正如你问题的副本所说,你的URL中有{} Spring将尝试填充{notification},但由于您没有提供它,它无法表示没有足够的变量值可用于展开“notif
final String notification = "{\"DATA\"}";
final String url = "http://{DATA}/create";
ResponseEntity<String> auth = create(address, name, psswd, url);
为什么?正如你问题的副本所说,你的URL中有
{}
Spring将尝试填充{notification}
,但由于您没有提供它,它无法表示没有足够的变量值可用于展开“notification”
您只需要传递通知字符串,这样Spring就可以正确构建URL
以下是此方法的示例:
private ResponseEntity<String> create(final String address, final String name,
final String newPassword, final String url) {
final Map<String, Object> param = new HashMap<>();
param.put("name", name);
param.put("password", newPassword);
param.put("email", address);
final HttpHeaders header = new HttpHeaders();
final HttpEntity<?> entity = new HttpEntity<Object>(param, header);
RestTemplate restTemplate = new RestTemplate();
return restTemplate.postForEntity(url, entity, String.class);
}
public <T> ResponseEntity<T> postForEntity(String url,
Object request,
Class<T> responseType,
Object... uriVariables)
throws RestClientException
Parameters:
url - the URL
request - the Object to be POSTed, may be null
responseType - the class of the response
uriVariables - the variables to expand the template
正如问题的副本所说,您的URL中有
{}
Spring将尝试填充{notification}
,但由于您没有提供它,它无法表示没有足够的变量值可用于展开“notification”
您只需要传递通知字符串,这样Spring就可以正确构建URL
以下是此方法的示例:
private ResponseEntity<String> create(final String address, final String name,
final String newPassword, final String url) {
final Map<String, Object> param = new HashMap<>();
param.put("name", name);
param.put("password", newPassword);
param.put("email", address);
final HttpHeaders header = new HttpHeaders();
final HttpEntity<?> entity = new HttpEntity<Object>(param, header);
RestTemplate restTemplate = new RestTemplate();
return restTemplate.postForEntity(url, entity, String.class);
}
public <T> ResponseEntity<T> postForEntity(String url,
Object request,
Class<T> responseType,
Object... uriVariables)
throws RestClientException
Parameters:
url - the URL
request - the Object to be POSTed, may be null
responseType - the class of the response
uriVariables - the variables to expand the template
正如问题的副本所说,您的URL中有
{}
Spring将尝试填充{notification}
,但由于您没有提供它,它无法表示没有足够的变量值可用于展开“notification”
您只需要传递通知字符串,这样Spring就可以正确构建URL
以下是此方法的示例:
private ResponseEntity<String> create(final String address, final String name,
final String newPassword, final String url) {
final Map<String, Object> param = new HashMap<>();
param.put("name", name);
param.put("password", newPassword);
param.put("email", address);
final HttpHeaders header = new HttpHeaders();
final HttpEntity<?> entity = new HttpEntity<Object>(param, header);
RestTemplate restTemplate = new RestTemplate();
return restTemplate.postForEntity(url, entity, String.class);
}
public <T> ResponseEntity<T> postForEntity(String url,
Object request,
Class<T> responseType,
Object... uriVariables)
throws RestClientException
Parameters:
url - the URL
request - the Object to be POSTed, may be null
responseType - the class of the response
uriVariables - the variables to expand the template
正如问题的副本所说,您的URL中有
{}
Spring将尝试填充{notification}
,但由于您没有提供它,它无法表示没有足够的变量值可用于展开“notification”
您只需要传递通知字符串,这样Spring就可以正确构建URL
以下是此方法的示例:
private ResponseEntity<String> create(final String address, final String name,
final String newPassword, final String url) {
final Map<String, Object> param = new HashMap<>();
param.put("name", name);
param.put("password", newPassword);
param.put("email", address);
final HttpHeaders header = new HttpHeaders();
final HttpEntity<?> entity = new HttpEntity<Object>(param, header);
RestTemplate restTemplate = new RestTemplate();
return restTemplate.postForEntity(url, entity, String.class);
}
public <T> ResponseEntity<T> postForEntity(String url,
Object request,
Class<T> responseType,
Object... uriVariables)
throws RestClientException
Parameters:
url - the URL
request - the Object to be POSTed, may be null
responseType - the class of the response
uriVariables - the variables to expand the template
下面的一行就足以让它工作了。我摆脱了关键人物,现在一切正常
final String url = "http://DATA/create";
下面的一行就足以让它工作了。我摆脱了关键人物,现在一切正常
final String url = "http://DATA/create";
下面的一行就足以让它工作了。我摆脱了关键人物,现在一切正常
final String url = "http://DATA/create";
下面的一行就足以让它工作了。我摆脱了关键人物,现在一切正常
final String url = "http://DATA/create";
@埃萨拉,你读过第一行了吗?你应该阅读问题正文,不仅是标题,而且是重复的。我从那里得到了您接受的答案,并用一些javadoc和示例完成了它。@ESala的确,这是一个重复的问题,所以我要删除这个问题。供未来读者参考:OP un接受了正确的答案。供未来读者参考:我错误地接受了@ESala不正确的答案。我的回答很有效。@ESala你读了第一行了吗?你应该阅读问题正文,不仅是标题,而且是重复的。我从那里得到了您接受的答案,并用一些javadoc和示例完成了它。@ESala的确,这是一个重复的问题,所以我要删除这个问题。供未来读者参考:OP un接受了正确的答案。供未来读者参考:我错误地接受了@ESala不正确的答案。我的回答很有效。@ESala你读了第一行了吗?你应该阅读问题正文,不仅是标题,而且是重复的。我从那里得到了您接受的答案,并用一些javadoc和示例完成了它。@ESala的确,这是一个重复的问题,所以我要删除这个问题。供未来读者参考:OP un接受了正确的答案。供未来读者参考:我错误地接受了@ESala不正确的答案。我的回答很有效。@ESala你读了第一行了吗?你应该阅读问题正文,不仅是标题,而且是重复的。我从那里得到了您接受的答案,并用一些javadoc和示例完成了它。@ESala的确,这是一个重复的问题,所以我要删除这个问题。供未来读者参考:OP un接受了正确的答案。供未来读者参考:我错误地接受了@ESala不正确的答案。我的回答奏效了。