0
点赞
收藏
分享

微信扫一扫

使用SpringBoot报错:Inferred type ‘S‘ for type parameter ‘S‘ is not within its bound。【解决办法】


❌一、错误展示

使用SpringBoot时出现如下错误:


Inferred type ‘S’ for type parameter ‘S’ is not within its bound


使用SpringBoot报错:Inferred type ‘S‘ for type parameter ‘S‘ is not within its bound。【解决办法】_spring boot

错误代码:

public Type updateType(Long id, Type type) {
Optional<Type> t = typeDao.findById(id);
if (t == null){
throw new NotFoundException("不存在该类型");
}
BeanUtils.copyProperties(type,t);
return typeDao.save(t);
}

✅二、解决办法

第一种:


将​​typeDao.findById(id);​​​改为​​typeDao.findById(id) .orElse(null);​


public Type updateType(Long id, Type type) {
Type t = typeDao.findById(id).orElse(null);
if (t == null){
throw new NotFoundException("不存在该类型");
}
BeanUtils.copyProperties(type,t);
return typeDao.save(t);
}

第二种:


将​​typeDao.findById(id);​​​改为​​typeDao.findById(id) .get();​


public Type updateType(Long id, Type type) {
Type t = typeDao.findById(id).get();
if (t == null){
throw new NotFoundException("不存在该类型");
}
BeanUtils.copyProperties(type,t);
return typeDao.save(t);
}

使用SpringBoot报错:Inferred type ‘S‘ for type parameter ‘S‘ is not within its bound。【解决办法】_spring boot_02



举报

相关推荐

0 条评论