How to define null-handling in Spring Data JPA sor

2019-05-10 09:16发布

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条回答
干净又极端
2楼-- · 2019-05-10 09:50

Spring Data's Sort object allows you to define:

Sort sort = new Sort(new Order(Direction.ASC, "property").nullsLast());
查看更多
登录 后发表回答