私たちのREST APIは結果をPagesに返します。ここに1つのコントローラの例がありますページ別APIを使用したSpring RestTemplate
RestTemplateでそのAPIを簡単に使用する方法はありますか?
我々は
ParameterizedTypeReference<Page<MyObject>> responseType = new ParameterizedTypeReference<Page<MyObject>>() { };
ResponseEntity<Page<MyObject>> result = restTemplate.exchange(url, HttpMethod.GET, null/*httpEntity*/, responseType);
List<MyObject> searchResult = result.getBody().getContent();
をすれば、それは例外
org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of org.springframework.data.domain.Page,
problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information at [Source: [email protected]; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of org.springframework.data.domain.Page, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
が
なぜヌルhttpEntityに渡し:Uは、(あなたが
"page"
セクションで何を得る)リンク("_links"
節)とコンテンツをページ・メタデータにアクセスすることができるでしょうか? null/* httpEntity */ –これは、正しいページ数または結果の合計数を返しません。 – ACOMIT001