(我正在使用 Micronaut)我有一个学生列表,我想按名称对其进行排序。我正在使用 Pageable 并排序为查询参数
http://localhost:8080/admin/students?page=0&size=10&sort=name,asc&status=graduated
我得到了这个结果:
- 萨曼莎
- 蒂姆
- 安东尼奥
- 大卫
- 苏菲亚
代替:
- 安东尼奥
- 大卫
- 萨曼莎
- 苏菲亚
- 蒂姆
我已经尝试了使用 Sort.Order 的选项,基于
PagingAndSortingRepository 如何排序不区分大小写?
Spring Data JPA:不区分大小写的 orderBy
我从我的网址中删除了排序并尝试了 Sort.Order 是否有效
Sort.Order order = new Sort.Order("name",Sort.Order.Direction.ASC, true);
http://localhost:8080/admin/students?page=0&size=10&status=graduated
但它没有,它也不做任何排序
脚步:
存储库,添加了 Sort.Order
@Repository public interface StudentRepository extends PageableRepository<Student, Long> { Page<Student> findByGraduatedIsNull(Student.Status status, @Nullable Pageable p, Sort.Order sort); }服务
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)); }
可能是什么问题呢?