部分代码片段:
@RequestMapping("getForEntity02")
public String getForEntity02(){
ResponseEntity result = restTemplate.getForEntity("http://localhost:8081/getForEntity02", List.class);
List body = result.getBody();
for (Object obj : body){
System.out.println(obj.getClass());
}
return "消费者---"+body;
}
以上我原本以为返回数据应该是User类型,但是依然是Map
所以总结: 如果服务提供者返回的是一个json数组的数据,那么我们消费者应该使用一个List集合来接收数据,但是集合中的泛型无论是什么类型,spring都不会自动进行转换,getForEntity方法返回的集合中的数据全部都是Map集合(linkedHashMap)



