SpringBoot在1.5.X版本中,传入id即可查询对象 :

xxxRepository.findOne(id);

但在2.X中,findOne改为了:

<S extends T> Optional<S> findOne(Example<S> var1);

getOne方法继续保留了,但是如果getOne(id)查询到的即使id不存在,也会返回该对象的引用,判断null无效。

后来找到了这种写法可以实现:

findOne. xxxRepository.findById(id).orElse(null)

相关文章:

  • 2021-04-12
  • 2022-12-23
  • 2021-08-25
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-04-18
  • 2022-12-23
猜你喜欢
  • 2022-02-21
  • 2022-12-23
  • 2021-08-27
  • 2022-01-21
  • 2021-10-31
  • 2021-08-07
  • 2022-03-04
相关资源
相似解决方案