Inferred type 'S' for type parameter 'S' is not within its bound
阿新 • • 發佈:2019-01-18
urn ping find spa pos 版本問題 osi class mapping
springboot報錯內容:
Inferred type ‘S’ for type parameter ‘S’ is not within its bound; should extends xxxxxx
/*
* 根據id查詢
*/
@GetMapping("/student/{id}")
public Student findById(@PathVariable("id") Integer id){
return studentRespository.findOne(id);
}
用以上方法findOne(id);報錯,經過網上查詢資料最後找到原因。解決辦法如下,
1、springboot 版本問題,將 2.0.1 版本換成 1.5.4 版本。
2、將studentRespository.findOne(id); 改為 studentRespository.findById(id).orElse(null);
3、將studentRespository.findOne(id); 改為
return studentRespository.findById(id).get();
4、將studentRespository.findOne(id); 改為
return studentRespository.getOne(id);
以上三種辦法,第二、三種方法本人試驗過可以使用,第一種本人沒進行驗證,如有需要可以自行驗證。第四種方法進行驗證因為jdk版本原因並未成功,所有推薦大家使用第二三種方法。
以上均來自個人驗證。
Inferred type 'S' for type parameter 'S' is not within its bound