繁体   English   中英

如何在Spring中合并两个ResponseEntity对象

[英]How to merge two ResponseEntity objects in Spring

我正在使用Spring 4.2。 我必须进行两个单独的http调用,它们返回ResponseEntity<String> 但是,我必须合并它们,然后再返回到调用方方法。

它们的数据结构完全相似。 只是内容不同。 如何在返回到调用者之前合并这两个实体?

使用rest模板可使您的实体进入要合并的实体。

final String uri = "http://localhost:8080/springrestexample/employees.xml";
RestTemplate restTemplate = new RestTemplate();
String result = restTemplate.getForObject(uri, String.class);

    final String uri2 = "http://localhost:8080/springrestexample/employees2.xml";
    RestTemplate restTemplate2 = new RestTemplate();
    String result2 = restTemplate.getForObject(uri, String.class);

return result1+result2; //or just your mergeMethod(result1,result2)

您还可以使用将实体与Collections框架或Java 8流图合并的服务来创建新端点。

您还可以创建一个更好的存储库数据访问对象,该对象将在数据库级别上联接表-sql,hql,jpql。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM