gpt4 book ai didi

grails - Grails/CreateCriteria-比较两个列表

转载 作者:行者123 更新时间:2023-12-02 15:05:38 24 4
gpt4 key购买 nike

通过使用CreateCriteria,我想比较两个列表,并检查groupsusers中是否存在至少一个元素。
有像eq这样的东西吗?


class User {
String login
static hasMany = [groups = String]
}

class Project {
String name
static hasMany = [users = User]
}

创建标准
def UserInstance = User.get(1)

def idList = Project.createCriteria().list () {

projections { distinct ( "id" )
property("name")
property("id")
}

eq("users.login", UserInstance.groups) //check if there are at least one element in groups list present in users list.
order("name","desc")

}

最佳答案

是的,您可以像这样使用inList(String propertyName, Collection c):

def UserInstance = User.get(1)

def idList = Project.withCriteria {

projections {
distinct("id")
property("name")
property("id")
}

users {
inList("login", UserInstance.groups)
}

order("name","desc")
}

关于grails - Grails/CreateCriteria-比较两个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32985689/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com