我正在做一个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/