हमारे आरईएसटी एपीआई पेजों में परिणाम लौट रहे हैं। यहां एक नियंत्रकस्प्रिंग रेस्ट टेम्पलेट पेजिनेटेड एपीआई
@RequestMapping(value = "/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
@ResponseStatus(HttpStatus.OK)
public Page<MyObject> findAll(Pageable pageable) {
...
}
क्या एक एपीआई को RestTemplate के साथ उपभोग करने का कोई आसान तरीका है?
हम
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 में पारित: यू पेज मेटाडाटा (क्या आप
"page"
खंड में मिलता है), लिंक ("_links"
अनुभाग) और सामग्री का उपयोग करने में सक्षम हो जाएगा? शून्य/* httpEntity */ –यह पृष्ठों की सही संख्या या परिणामों की कुल संख्या वापस नहीं करता है। – ACOMIT001