嗨,我希望客户端能够使用一个安静的网络服务。我使用 springboot,该服务返回一个仅包含一个对象的 JSON 列表。 我想像这样使用 RestTemplate 的 postForObject Api
ResponseEntity<List<RetrieveRichiestaResponseDto>> result = restTemplate.postForObject(
uri,
entity,
new ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>() {});
为什么它给我这个错误
> The method postForObject(String, Object, Class<T>, Object...) in the
> type RestTemplate is not applicable for the arguments (String,
> HttpEntity<capture#3-of ?>, new
> ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>(){})
感谢帮助!
最佳答案
restTemplate.postForObject()
不支持ParameterizedTypeReference<>
使用restTemplate.exchange()
ResponseEntity<List<RetrieveRichiestaResponseDto>> result = restTemplate.exchange(uri, HttpMethod.POST, entity,
new ParameterizedTypeReference<List<RetrieveRichiestaResponseDto>>() {});
关于java - RestTemplate.postForObject 和列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61248957/