1. 程式人生 > >Inferred type 'S' for type parameter 'S' is not within its bound

Inferred type 'S' for type parameter 'S' is not within its bound

urn ping find spa pos 版本問題 osi class mapping

springboot報錯內容:
Inferred type ‘S’ for type parameter ‘S’ is not within its bound; should extends xxxxxx

/*

  1. * 根據id查詢
  2. */
  3. @GetMapping("/student/{id}")
  4. public Student findById(@PathVariable("id") Integer id){
  5. return studentRespository.findOne(id);
  6. }

用以上方法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