1

我有一个通用类:

BaseResponseDTO<T>
{
    T payload;
}

我正在进行返回此对象的 REST 调用:

String url = "http://REST-CALL-LINK";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
BaseResponseDTO<UserDTO> requestMap = new BaseResponseDTO<UserDTO>();
HttpEntity<BaseResponseDTO<UserDTO>> reqEntity = new HttpEntity<BaseResponseDTO<UserDTO>>(requestMap, headers);
BaseResponseDTO<UserDTO> response = new BaseResponseDTO<UserDTO>(new UserDTO());
ResponseEntity<BaseResponseDTO<UserDTO>> responseUnifiedDTO = restTemplate.exchange(url, HttpMethod.GET, reqEntity, response.getClass());
UserDTO user = responseUnifiedDTO.getBody().getPayload();

这段代码给了我错误:

Type mismatch: cannot convert from ResponseEntity<capture#2-of ? extends BaseResponseDTO> to ResponseEntity<BaseResponseDTO<UserDTO>>
4

0 回答 0