dot*_*otS 3 spring pagination spring-data-jpa spring-boot
NULL LAST不适用于弹簧数据 JPA。
这是我正在使用的代码。
服务层代码:
Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "user_name").nullsLast());
Pageable pageable = PageRequest.of(0, 10, sort);
userRepository.findAllUsers(pageable)
Run Code Online (Sandbox Code Playgroud)
回购层代码:
@Query(value = "Select * from users", nativeQuery = true)
Page<User> findAllUsers(Pageable pageable);
Run Code Online (Sandbox Code Playgroud)
预期/实际输出:
Expected: Null values should come at the last
Actual: Null values are coming at the top
Run Code Online (Sandbox Code Playgroud)
使用
Spring Boot version: **2.1.6.RELEASE**
Database Postgres version: **42.2.5**
Run Code Online (Sandbox Code Playgroud)
有哪位朋友可以帮帮我吗?
我搜索了很多博客,但是你不能在存储库方法中写这个。您可以在 application.properties 中使用以下配置。我正在使用 Spring Boot 2.1.9.RELEASE。它为我工作。spring.jpa.properties.hibernate.order_by.default_null_ordering=last
| 归档时间: |
|
| 查看次数: |
2513 次 |
| 最近记录: |