java - JPA 选择多个字段

标签 java mysql spring jpa jdbc

是否可以在 jpql 中实现类似下面的 mySQL 的功能?

select * from PERSON p where (p.name, p.country)
IN (('Bryan', 'Netherlands'), ('Candice', 'New Zealand'), ...);

其中“...”是列表的延续。我想创建一个新实体列表作为值的占位符,但我不确定如何使其工作。我正在考虑以下内容:

    @Query(
        value = "select p from Person p where (p.name, p.country) in :personList")
    List<Person> findPersonsIn(@Param("personList") List<Person> personList);

我知道这是非常错误的,但我希望有人能够阐明如何在 JPA 或 JDBC 中实现上述 MySQL 语句。

最佳答案

是的。使用 AND 运算符:

select * from PERSON p where ( p.name IN ('Bryan', 'Netherlands') ) AND ( p.country
IN ('Candice', 'New Zealand') ), ...);

关于java - JPA 选择多个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61205029/

相关文章:

java - 构建 apk 时出错 'libraries must use the exact same version specification'

java - JAR 文件未包含在 Android Ant 构建中

mysql - XAMPP : MySQL shutdown unexpectedly INNODB warnings

mysql - 试图使RmySQL工作,但不了解bash的导出或文件系统约定

java - Spring LibGDX And​​roid 应用程序中缺少 java.beans.Introspector

java - 在图上实现传输

java - 如何使用setter为私有(private)数组的属性设置值?

php - 检索记录并使用字符串函数将其转换为新记录

java - Spring @Scheduled 计时器精度

java - Spring AOP Autowiring 异常