I using micronuat Data with JPA to access the MySQL table. findall return all the data, now I want sort the output by createdat
datetime filed.
@Get("/")
List<Book> all() {
return bookRepository.findAll()
}
How to sort this value by createdat field? Thanks
How to sort this value by createdat field?
A simple way is to add a listOrderByCreatedat()
method to your repository.
@Repository
public interface BookRepository extends CrudRepository<Book, Long> {
List<Book> listOrderByCreatedat();
}