Is there a way to get the latest number of X results from a query?
For example, if you want to get the first ten results, I see that this example works: setMaxResults for Spring -Data-JPA annotations?
public interface UserRepository extends Repository<User, Long> {
List<User> findByUsername(String username, Pageable pageable);
}
Pageable topTen = new PageRequest(0, 10);
List<User> result = repository.findByUsername("Matthews", topTen);
But how do I get the last 10 entries?
The only way I could do this is to flip the order in the query (findByUsernameDesc, assuming the original results were upstream) and then iterate over the list back so that I can process it in the order I wanted (ascending) ,
It seems like an ugly way to do it. Is there a way for the query to give me the latest X results in the order I want?