当我用休息客户端软件调用它时,我的休息服务器正在生成响应。当我用上面提到的 resttemplate
代码调用它时,服务器生成响应(打印日志)但是 resttemplate
什么都不做(调用后没有下一行执行)并打印 internal错误。
这是我服务器中的方法
@ResponseBody
public ResponseEntity<Map<String, Object>> name(){......
...
return new ResponseEntity<Map<String, Object>>(messagebody, HttpStatus.OK);
}
这是我通过restTemplate调用它的方式
ResponseEntity<Map> response1 = restTemplate.getForEntity(finalUrl.toString(), Map.class);
最佳答案
尝试使用ParameterizedTypeReference而不是通配符 Map。 它应该看起来像这样。
ParameterizedTypeReference<Map<String, Object>> typeRef = new ParameterizedTypeReference<Map<String, Object>>() {};
ResponseEntity<Map<String, Object>> response = restTemplate.exchange(finalUrl.toString(), HttpMethod.GET, null, typeRef);
关于java - Spring restTemplate 获取响应的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28855023/