我有这个 Spring Boot Data JPA 存储库:
@Query(value = """
SELECT .......
""", nativeQuery = true)
ProfileView findByCustomerId(......);
投影:
public interface ProfileView {
String getRreference();
}
查询:
final ProfileView result = profileRepository.findByCustomerId(......);
final String profile = result.getReference();
我收到错误:
java.lang.NullPointerException: Cannot invoke "com.ProfileView.getReference()" because "result" is null
我的 SQL 查询结果为空。你知道我该如何解决这个问题吗?我需要一个没有 NPE 错误的空
String profile
。
使用可选
@Query(value = """
SELECT .......
""", nativeQuery = true)
Optional<ProfileView> findByCustomerId(......);