在spring boot(1.4.1)应用程序中,我尝试使用其余模板
@GetMapping(value = "/visits")
public ResponseEntity<CustomPageImpl<VisitDto>> getVisits(Pageable pageRequest) {
return restTemplate.getForEntity("", new TypeReference<CustomPageImpl<VisitDto>>() {});
}
像在这个thread中的Ali Dehghani的回答一样,我创建了一个CustomPageImpl
关于TypeReference,导入com.fasterxml.jackson.core.type.TypeReference;
我收到此消息
no suitable method found for getForEntity(String,<anonymous TypeReference<CustomPageImpl<VisitDto>>>)
method RestTemplate.<T#1>getForEntity(String,Class<T#1>,Object...) is not applicable
(cannot infer type-variable(s) T#1
(argument mismatch; <anonymous TypeReference<CustomPageImpl<VisitDto>>> cannot be converted to Class<T#1>))
method RestTemplate.<T#2>getForEntity(String,Class<T#2>,Map<String,?>) is not applicable
(cannot infer type-variable(s) T#2
(actual and formal argument lists differ in length))
method RestTemplate.<T#3>getForEntity(URI,Class<T#3>) is not applicable
(cannot infer type-variable(s) T#3
(argument mismatch; String cannot be converted to URI))
where T#1,T#2,T#3 are type-variables:
T#1 extends Object declared in method <T#1>getForEntity(String,Class<T#1>,Object...)
T#2 extends Object declared in method <T#2>getForEntity(String,Class<T#2>,Map<String,?>)
T#3 extends Object declared in method <T#3>getForEntity(URI,Class<T#3>)
用
ResponseEntity<CustomPageImpl<VisitDto>> response = restTemplate.getForEntity(URI.create("url"), new TypeReference<ResponseEntity<CustomPageImpl<VisitDto>>>() {});
得到同样的错误
答案 0 :(得分:-1)
尝试getForEntity(URI url,Class responseType)
@GetMapping(value = "/visits")
public ResponseEntity<CustomPageImpl<VisitDto>> getVisits(Pageable pageRequest) {
ResponseEntity<CustomPageImpl<VisitDto>> response = restTemplate.getForEntity(Uri.parse("url"), new TypeReference<CustomPageImpl<VisitDto>>() {});
return response;
}