如何在Spring Data JPA排序中定义空处理? [英] How to define null-handling in Spring Data JPA sorts?

查看:209
本文介绍了如何在Spring Data JPA排序中定义空处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将我的数据按null排序,而不是仅按null排序.如下所示:

I need my data to be ordered by null and not null only. Like below:

Column A
null 
null 
null
8 
10
5

意味着一旦所有null值都在最上面,其余的值就根本不应排序,而是照原样进行. 知道如何使用jpa查询/本机查询来完成此操作.

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.

推荐答案

Spring Data的Sort对象允许您定义:

Spring Data's Sort object allows you to define:

Sort sort = new Sort(new Order(Direction.ASC, "property").nullsLast());

这篇关于如何在Spring Data JPA排序中定义空处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆