gpt4 book ai didi

java - 使用 RestTemplate 获取模型对象

转载 作者:行者123 更新时间:2023-12-01 10:51:22 25 4
gpt4 key购买 nike

我尝试使用 org.springframework.web.client.RestTemplate.RestTemplate() 及其方法在列表中加载对象模型:

List<Document>  l = restTemplate.getForEntity("url", "class")

另一方面,有一个使用 springWeb 实现的 webService,如下所示:

@RequestMapping(value = "/documents", method = RequestMethod.GET)
public ResponseEntity<ServiceResponse> list() {
LOGGER.info(String.format("CALL : /rest/documents"));

return new ResponseEntity<ServiceResponse>(new ServiceResponse(Code.OK, documentService.list()), HttpStatus.OK);
}

如何从restTemplate.getForEntity返回的responseEntity<>中提取列表?

情况正在演变。我这样做了:

ResponseEntity<ServiceResponse> quote = restTemplate.getForEntity("https://apps.athena-software.fr/edocsol-ground-backend/rest/documents",
ServiceResponse.class);

List l = (List) quote.getBody().getResponse();

我现在有一个列表,其中 Map 的每个键都是对象“Document”的一个字段,我需要做一个转换器才能从您认为的列表“Map”中获取列表“Document”或者有什么东西这样做吗?

最佳答案

该列表被包装到 ServiceResponse 中,因此您需要映射到此类:

ServiceResponse serviceResponse = restTemplate.getForEntity("url", ServiceResponse.class);
List<Document> list = serviceResponse.getList(); // or whatever the method is called

关于java - 使用 RestTemplate 获取模型对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33867583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com