在java中,为了判断查询的类对象是否存在,采用此方法:

eg:

public ShopHomeView findByOwnerIds(String ownerId) {

Optional<ShopHomeView> view = shopHomeViewRepository.findByOwnerId(ownerId);
if(view.isPresent()) {
return view.get();
}else {
return null;
}
}

.isPresent()一般与.get()方法合用,当view存在时,view.isPresent()值为true,通过get()方法返回对象。

 

相关文章:

  • 2021-11-26
  • 2021-08-06
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2022-01-08
  • 2021-04-13
  • 2021-11-09
  • 2022-03-05
  • 2021-07-21
相关资源
相似解决方案