Spring Data JpaRepository findAll(Iterable<ID> ids) + findAll(Sort sort)

18,408

Just declare a query method like this:

public interface UserRepository extends Repository<User, Integer> {

  Iterable<User> findByIdIn(Collection<Integer> ids, Sort sort);
}
Share:
18,408

Related videos on Youtube

Channa
Author by

Channa

Think before code

Updated on September 15, 2022

Comments

  • Channa
    Channa over 1 year

    With Spring Data JpaRepository is there any capability to get select collection of given Id with some sorting. That mean I need to make enable following query. I have found some solution apply with @NamedQuery but I can't make enable it because I am using Spring-data-jap 1.4.2.RELEASE. Thanks.

    public Iterable<User> findAll(Iterable<Integer> userIds) {
    
     Sort sort = new Sort(Direction.ASC, "name");
    
     Iterable<User> users = userRepository.findAll(userIds, sort); 
    
     return users; 
    }