I'm using Spring PagingAndSortingRepository and I have a very easy findAll query:
inventoryDao.findAll(new Sort(Sort.Direction.DESC,"startTime"))
It's working fine, I just was wondering: is it possible to replace the query above using Method Name generation instead? (Somethnig like: inventoryDao.findAllOrderByStartTime() )
You have to use findAllByOrderBy...
As the Spring Data documentation says, the first by in the method name acts as delimiter to indicate the start of the actual criteria, in your case the sorting so it's necessary to add this in the method name before Order word.
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