带有不同且不为空的JPA查询

问题描述

如何在春季启动时使用 NSError *bookMarkError; NSData *bookmarkData = [url bookmarkDataWithOptions:NSURLBookmarkCreationMinimalBookmark includingResourceValuesForKeys: nil relativeToURL:nil error:&bookMarkError]; BOOL isStale = false; BOOL isScopedURL = false; NSError *error; NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmarkData options: 0 relativeToURL:nil bookmarkDataIsStale:&isStale error:&error]; if (isStale) { } if (error) { } // Note that it does not come back as stale,and I don't get any error if (resolvedURL) { BOOL accessGranted = [resolvedURL startAccessingSecurityScopedResource]; //<==== returns false accessGranted = [url startAccessingSecurityScopedResource]; //<===== returns true } distinct编写jpa查询?下面是示例。

员工实体类 sql查询是:

not null

如何在jpa中编写以上查询。

我在这里select distinct job from emp where job is not null 尝试过findByJobNotNull()正常,但是需要null怎么做,请提出建议。

enter image description here

解决方法

只需将#include添加到方法名称

Distinct
,
  1. 您可以使用以下查询:
@Query("select distinct e.job from Employee e where e.job is not null")
List<String> findJobs();
  1. 您可以使用projections

假设您拥有:

@Entity
class Employee {
   // ...

   @Column(name = "job")
   public String getJob()
   {
      return job;
   }
}

您可以创建基于接口的投影:

public interface EmployeeJob
{
   String getJob();
}

,然后将以下方法添加到您的Employee存储库:

List<EmployeeJob> findDistinctByJobNotNull();

您可以在documentation中找到其他信息。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...