Spring Boot CrudRepository搜索@ElementCollection映射键

时间:2018-04-21 13:05:38

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

我有一个实体:

@Id
Long id

String username;

@ElementCollection
private Map<String, Boolean> emails;

我有存储库:

public interface UserRepository extends CrudRepository<User, Long>, UserDao {
    User findOneByUsername(String username);

    // This does not work, how do I make it?
    @Query("select u from User u WHERE ? in u.emails.keySet")
    User findOneByQueryForEmail
}

我可以使用哪种方法签名(和@Query注释)来实现findOneByQueryForEmail来搜索keySet电子邮件Map的值?

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方法

@Query("select u from User u WHERE KEY(u.emails) in :emails")

 User findOneByQueryForEmail(@Param("emails") List<String> emails)