I have a Spring Data REST service with a single @Entity and Repository. When I run
I get all the data stored in my repository and it works as expected. I also have a small React front end and I display that data there.
My question is: Where should I filter the data? For example maybe I want all the entries with id > 10. Should I just filter the response in my front end or should I make the REST call in such a way that it returns just the required entries?
If I should do the latter, then how?
If it is always the case, why would you put extra burden on
front-end shoulders to filter the results all the time?
Implement a new method which returns the desired results(e.g id > 10) and annotate it with
@Query and provide
native query inside it
@Query("SELECT c FROM Customer c WHERE c.id > 10") Collection<Customer> findAllActiveCustomers();
However, if you choose native query do not forget to put
nativeQuery = true inside