简体   繁体   中英

JpaRepository query “in” (Hibernate)

I have a JpaRepository:

public interface UserRepository extends JpaRepository<User, Long> {
    List<User> getByFirstName(String firstName);
}

But how to search in several values? I need something like this:

List<User> getByFirstNames(List<String> firstNames);

You need to change the signature of the method to:

List<User> getByFirstNameIn(List<String> firstNames);

Take a look at all the supported method of Spring Data JPA on their reference .

The following code is working, Code in Repository,

List<Shop> findByNameIn(List<String> names);

Code in controller,

List<String> names=new ArrayList<String>();
names.add("gunaa");
names.add("pranav");

List<Shop> sl=shopService.findByNameIn(names);
for(Shop s:sl)
    System.out.println(s.getName());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM