Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails 按特定属性值对hql结果排序_Grails_Groovy_Hql - Fatal编程技术网

Grails 按特定属性值对hql结果排序

Grails 按特定属性值对hql结果排序,grails,groovy,hql,Grails,Groovy,Hql,我有一个域,其中包含一个名为“Status”的属性。 此属性可以包含“A”、“I”、“P”、“Pv”、“R” 我有以下疑问: def list = Deal.findAll('from Deal as d') 如何对结果进行排序,使状态为“p”的行始终返回到结果集的顶部?(我不在乎他们之后的顺序。)这能满足你的要求吗?通常我会在回答之前测试一下,但我没有一个简单的方法 def list = Deal.findAll('''from Deal as d order by case d.prope

我有一个域,其中包含一个名为“Status”的属性。 此属性可以包含“A”、“I”、“P”、“Pv”、“R”

我有以下疑问:

def list = Deal.findAll('from Deal as d')

如何对结果进行排序,使状态为“p”的行始终返回到结果集的顶部?(我不在乎他们之后的顺序。)

这能满足你的要求吗?通常我会在回答之前测试一下,但我没有一个简单的方法

def list = Deal.findAll('''from Deal as d order by case d.property when 'P' then 0 else 1 end''')

您可以将排序方法与比较器一起使用:

def list = Deal.findAll('from Deal as d').sort({a,b-> (a.status== 'P' && b.status != 'P') ? 0 : 1 })

获取所有
其中d.property=='P'
,然后获取由d.property排序的所有其他
,并在客户端合并它们,这会是一个问题吗?例如:
def list=Deal.findAll('from Deal as d,其中d.prop==“P”);list.addAll(Deal.findAll('from Deal as d其中d.prop“P”order by d.prop))
(顺便说一下,这是元语法。根据您的需要进行调整。)def list=Deal.findAll('from Deal as d order by(d.status='P')创建映射并转换到
比较器是不必要的。您只需传递闭包
{a,b->(a.status='P'&b.status!='P'))?0:1}
sort()
方法。