(I'm using Micronaut) I have a list of students and I want to sort it by name. I am using Pageable and sort as query parameters
http://localhost:8080/admin/students?page=0&size=10&sort=name,asc&status=graduated
and I get this result:
- Samantha
- Tim
- antonio
- david
- sofia
Instead of:
- antonio
- david
- Samantha
- sofia
- Tim
I have tried the options using Sort.Order, based on
PagingAndSortingRepository how to sort case insensitive?
Spring Data JPA: case insensitive orderBy
I removed the sorting from my url and tried if Sort.Order works
Sort.Order order = new Sort.Order("name",Sort.Order.Direction.ASC, true);
http://localhost:8080/admin/students?page=0&size=10&status=graduated
but it didn't, it doesn't do any sorting neither
Steps:
Repository, added Sort.Order
@Repository public interface StudentRepository extends PageableRepository<Student, Long> { Page<Student> findByGraduatedIsNull(Student.Status status, @Nullable Pageable p, Sort.Order sort); }
Service
public Page<Student> getStudents(Student.Status status, Pageable pageable){ Sort.Order order = new Sort.Order("name",Sort.Order.Direction.ASC, true); Page<Student> studentPage = studentRepository.findByGraduatedIsNull(status, pageable, order); return studentPage.map(s -> studentTransform.toDto(s)); }
What could be the problem?