我有一个接口公共接口IAllAccountsRepo扩展CrudRepository春天JPA查询findByNameAndType返回NULL
,并像下面
@Query(value = "SELECT * FROM account a where a.id in :id AND a.accountType = :accountType", nativeQuery=true)
public AccountEntity findByIdAndAccountType(@Param("id") String id, @Param("accountType") String accountType);
当我把这种方法在一个辅助类的一个方法,在那里我会得到一个ID和I列表循环遍历它们并将过滤器值传递给上述方法,但当没有与数据库中的查询匹配的记录时,我遇到了问题。
它只是停止说空(当在db中没有记录)。我不想通过例外,如果我能做到这一点,需要忽略并继续。无论如何,我可以编码它忽略null并继续?或者我需要标准查询还是其他?
for (String id : accountIdList) { accountEntityTemp = iAllAccountsRepo.findByIdAndAccounttype(id, accounttype); System.out.println("bs" + accountEntityTemp.getId()); if (accountEntityTemp != null) { accountsEntityList.add(accountEntityTemp); } }
accountEntityTemp = null为一个id和accounttype,我得到下面的错误。
2015年12月10日14:20:03.784 WARN 10524 --- [NIO-8080-EXEC-1] .m.m.a.ExceptionHandlerExceptionResolver:处理程序执行导致异常:空
感谢。
经过春季文档后,我改变了一切,但问题是印刷声明是愚蠢的。非常感谢。 – Arun