Search code examples
jpamicronautmicronaut-data

Micronuat Data Entity findAll order by createddate desc


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


Solution

  • 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();
    }