0

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

sfgroups
  • 18,151
  • 28
  • 132
  • 204

1 Answers1

0

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();
}
Jeff Scott Brown
  • 26,804
  • 2
  • 30
  • 47