问题
I need my data to be ordered by null and not null only. Like below:
Column A
null
null
null
8
10
5
Meaning once all the null values are on top, the rest of the values should not be sorted at all and come as is. Any idea how this can be done using jpa query/ native query.
回答1:
Spring Data's Sort
object allows you to define:
Sort sort = new Sort(new Order(Direction.ASC, "property").nullsLast());
回答2:
Use JPQL and you will be happy.
SELET f FROM Foo f ORDER BY f.name NULLS LAST
来源:https://stackoverflow.com/questions/29401227/how-to-define-null-handling-in-spring-data-jpa-sorts