Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.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
如何执行SQl where查询并正确列出?_Sql_Grails_Groovy_Where - Fatal编程技术网

如何执行SQl where查询并正确列出?

如何执行SQl where查询并正确列出?,sql,grails,groovy,where,Sql,Grails,Groovy,Where,我正在尝试执行以下操作: def query = Scholarship.withCriteria { eq('activeInd', "A") } allInfo = query.list(sort: "name", order: "asc") return allInfo } 我以前使用过这个,但现在我需要将其更改为上面的内容: def allInfo = Scholarship.list(sort: "name", order: "asc") 我需要使用activeInd fie

我正在尝试执行以下操作:

def query = Scholarship.withCriteria {
  eq('activeInd', "A")
}
allInfo = query.list(sort: "name", order: "asc")

return allInfo
}
我以前使用过这个,但现在我需要将其更改为上面的内容:

def allInfo = Scholarship.list(sort: "name", order: "asc")
我需要使用activeInd field=A获取所有奖学金对象。然后我需要在这些对象上使用.list以基于名称的升序获取列表/数组中的所有奖学金。我遇到的错误如下:


方法java.util.ArrayList.list()的签名不适用于参数类型:()值:[]可能的解决方案:last()、last()、first()、first()、is(java.lang.Object)、toList()

,因为您正在对带条件的
的结果使用
list()
。这可以通过以下三种方式之一解决:

def result = Scholarship.createCriteria().list(sort: 'name', order: 'asc') {
    eq('activeInd', "A")

    //alternatively
    //order('name', 'asc')
}

我更喜欢使用where的第三种方法

def result = Scholarship.withCriteria {
    eq('activeInd', "A")
    order('name', 'asc')
}
def result = Scholarship.where {
    activeInd == 'A'
}.list(sort: 'name', order: 'asc')