Spring 数据: can it find by two values of the same field without writing the implementation?

标签 spring spring-data spring-data-jpa

我正在做一个Spring Web应用程序,并且使用Spring Data。

我能够使用Spring Data通过字段的单个值查找对象。例如:

some_object_repository.findByFirstName("John") 

有什么办法可以提供两个与概念类似的名字(例如“John”,“David”):
some_object_repository.findByFirstName({"John", "David"})

没有我编写自定义实现?

谢谢,谢谢!

最佳答案

您可以在最后使用In进行此操作

findByAgeIn(Collection ages) … where x.age in ?1



http://docs.spring.io/spring-data/jpa/docs/1.6.0.RELEASE/reference/html/jpa.repositories.html#jpa.query-methods

2.3.2节查询创建

在你的情况下

findByFirstNameIn(Collection names)

关于 Spring 数据: can it find by two values of the same field without writing the implementation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23902954/

相关文章:

java - Spring Data JPA NamedStoredProcedureQuery 多个输出参数

java - 如何将 Spring MVC 连接到远程 MongoDB,以使用 MongoOperations 接口(interface)?

html - 在 Thymeleaf 中创建下拉菜单和表单

java - Spring 数据JPA : externalize to a property file the @EnableJpaRepositories basePackages configuration

java - 我正在尝试将 mongodb 与 spring boot 连接。我很困惑何时使用以下 : 中的哪个 Maven 依赖项

spring-data-jpa - java.lang.IllegalArgumentException : Parameter with that position [1] did not exist

mysql - UUID 在此位置无效(Mysql 工作台)

Java,更改 PC 上的时区后测试失败

java - JdbcTemplate 与 TransactionManager 究竟如何协同工作?

java - 获取特定列 JPA、Spring boot