【问题标题】:how to write not in clause using springboot findAll() method如何使用spring boot findAll()方法编写not in子句
【发布时间】:2019-08-31 15:09:25
【问题描述】:

我尝试使用 spring boot JPA 和 CRUD Repository findAll() 方法从数据库中获取数据,并使用 not in 子句,但找不到任何位置。有任何使用 findAll() 方法进行动态查询的解决方案。

示例:

hql="select * from urlMaster urlmast where urlmast.urlcd not in (select distinct acturl.acuCd from ActionUrl acturl) order by urlmast.urlcd";

目前我只是从 urlMaster 数据中获取数据。但我想要 acturl.acuCd not in ActionUrl 表。

存储库类

public interface ActionUrlRepository extends CrudRepository<urlMaster, Long>,JpaRepository<urlMaster, Long> {

}

服务实现:

actionurlrepository.findAll();

如果有什么规定?请指导我。谢谢!

【问题讨论】:

  • 为什么findAll() 会限制结果?我想我不明白你的问题。
  • Jens Schauder!- 我想要基于豪宅查询的数据库中的数据。 Springboot 已经有一些预定义的方法,如 findAll()...等以及 springboot 中的各种存储库。同样,我将根据带有 not in 子句的 that 方法构建标准。如果你有什么解决办法?让我们发布。我知道@Query 已经有了。我正在寻找那种情况。一些互联网指南告诉解决方案,但没有得到确切的解决方案。-谢谢

标签: java spring spring-boot jpa spring-data-jpa


【解决方案1】:

您可以将查询字符串放在@Query 注释中,如https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query 中所述

类似:

public interface ActionUrlRepository extends JpaRepository<urlMaster, Long> {

    @Query("select * from urlMaster urlmast where urlmast.urlcd not in (select distinct acturl.acuCd from ActionUrl acturl) order by urlmast.urlcd")
    List<urlMaster> findByNotIn();
}

顺便说一句,声明中不需要 CrudRepository,因为 JpaRepository 已经从它扩展(通过 PagingAndSortingRepository)。

【讨论】:

  • 谢谢!我期待 findll() 有任何规定包括 ..?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-14
  • 1970-01-01
  • 2011-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多