Spring boot error:Inferred type ‘S’ for type parameter ‘S’ is not within its bound; should extend XXX
在学习《Mu客网廖师兄两小时学会SpringBoot》的课程数据库操作中,如下代码片段
@GetMapping(value="/girls/{id}")
public Girl girlFindOne(@PathVariable("id") Integer id) {
return girlRepository.findOne(id);
如果采用了较新版本的spring boot,会报以下错误:
Inferred type 'S' for type parameter 'S' is not within its bound; should extend 'com.learn.girl.Girl'
原因:廖老师的spring boot采用了1.4.1.RELEASE,而新版一般是2.0以上
解决方案:替换findOne方法
return girlRepository.findById(id).orElse(null);