错误为getSingleResult();获取值时获取不到报异常。

getSingleResult的源码有一句: @throws EntityNotFoundException if there is no result

查不到结果时,它是抛异常的,不会返回null.
解决方式,将异常捕捉
try{
Query query =this.getJpaTemplate().getEntityManager().createNativeQuery(sql,SmpRole.class);
obj = (SmpRole)query.getSingleResult();

    }catch(NoResultException e){
return null;
    }

相关文章:

  • 2021-12-15
  • 2021-10-01
  • 2021-10-15
  • 2022-01-10
  • 2022-01-19
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2022-01-01
  • 2021-12-20
相关资源
相似解决方案