我正在使用rest模板调用外部url;
下面是我的React模式
class College{
private int id;
private String name;
-----
}
class ResponseModel <T>{
private int response;
private List<T> data;
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<Model> entity = new HttpEntity<>(model, headers);
我试过的第一种方法
ParameterizedTypeReference<ResponseModel<College>> typeRef = new ParameterizedTypeReference<ResponseModel<College>>() {};
ResponseEntity<ResponseModel<College>> responseEntity = restTemplate.exchange(serverUrl, HttpMethod.POST, entity, typeRef);
ResponseModel<College> responseData = responseEntity.getBody();
我试过的第二种方法
ResponseModel<College> responseData = restTemplate.postForObject(serverUrl,entity,ResponseModel.class)
List<College> college = responseData.getData()
我没有得到我的列表对象。当我打印responsedata时,它在列表中显示数据,但当我在college对象中获取列表时,它显示所有键为空。
暂无答案!
目前还没有任何答案,快来回答吧!