如何从 JPA 获取不同的记录 [英] How to get Distinct record from JPA

查看:39
本文介绍了如何从 JPA 获取不同的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个给我规范的方法,但我想要的是查询应该如下:

I have implemented a method which gives me specification, but what I want is the query should be as below:

Select Distinct * 
From (another select query)

我动态生成查询.

如何在 Spring Boot 中使用规范执行相同的操作?

How do I perform the same using specification in Spring Boot?

推荐答案

如果你想获得不同的记录,你必须在存储库中编写这样的查询.

if you want to get distinct records, you have to write a query like this in the repository.

下面的查询给出了 post 表中不同的作者.

The below query gives the distinct author from the post table.

@Query("select distinct author from Post")
    List<String> findUniqueAuthor();

这篇关于如何从 JPA 获取不同的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆