I want to add in my Repository interface a method which find all the data greater than a long publishdata
value and Order it Decreacingly:
I tried this, but it doesn't seems to be working:
@Repository
public interface NoticiaRepository extends CrudRepository<Noticia,Long>{
Noticia findById(long id);
List<Noticia> findByOrderPublishdateGreaterThanDesc(long publishdate);
}
With JPA Criteria – the orderBy method is a “one stop” alternative to set all sorting parameters: both the order direction and the attributes to sort by can be set. Following is the method's API: orderBy(CriteriaBuilder. asc): Sorts in ascending order.
Using a Sort Object With Spring Data JPA, you can also add a parameter of type Sort to your method definition. Spring Data JPA will then generate the required ORDER BY clause. That is the same approach as you can use in a derived query.
One option is to use Spring Data's method derivation, whereby the query is generated from the method name and signature. All we need to do here to sort our data is include the keyword OrderBy in our method name, along with the property name(s) and direction (Asc or Desc) by which we want to sort.
Crud Repository doesn't provide methods for implementing pagination and sorting. JpaRepository ties your repositories to the JPA persistence technology so it should be avoided. We should use CrudRepository or PagingAndSortingRepository depending on whether you need sorting and paging or not.
List<Noticia> findByPublishdateGreaterThanOrderByPublishdateDesc(Long publishdate)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With