【发布时间】:2021-05-18 05:11:16
【问题描述】:
(我正在使用 Micronaut) 我有一个学生列表,我想按名称对其进行排序。我正在使用 Pageable 并作为查询参数排序
http://localhost:8080/admin/students?page=0&size=10&sort=name,asc&status=graduated
我得到了这个结果:
- 萨曼莎
- 蒂姆
- 安东尼奥
- 大卫
- 索菲亚
代替:
- 安东尼奥
- 大卫
- 萨曼莎
- 索菲亚
- 蒂姆
我已经尝试了使用 Sort.Order 的选项,基于
PagingAndSortingRepository how to sort case insensitive?
Spring Data JPA: case insensitive 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)); }
可能是什么问题?
【问题讨论】:
标签: java spring spring-boot jpa pageable