在groovy中遍历另一个列表中的列表

在groovy中遍历另一个列表中的列表,groovy,Groovy,我需要迭代组列表中的用户列表,如果用户列表中有组(来自组列表),我需要将其从用户列表中删除。我尝试了以下方法,但不起作用 def groupsList = entity.companyContainer.groups groupsList.each { g -> g.users.each { u -> if( u.groups.find( g ) ) { u.groups.remove( g ) entityServi

我需要迭代组列表中的用户列表,如果用户列表中有组(来自组列表),我需要将其从用户列表中删除。我尝试了以下方法,但不起作用

def groupsList = entity.companyContainer.groups
groupsList.each { g ->
    g.users.each { u ->
       if( u.groups.find( g ) ) {
           u.groups.remove( g )
           entityService.update( u )  
       }
    }
    entityService.delete(g)
}
例外情况:

ERROR | com.core.common.controller.impl.BaseMultiActionController | groovy.lang.MissingMethodException:
No signature of method: 
    com.core.configuration.persistence.ListWithPersistentSetPropertyAccessor$ListWit‌​hPersistentSet.find()
    is applicable for argument types: (com.core.security.model.impl.Group) values: [LFO Super Users_Lawfirm]
 Possible solutions: find(groovy.lang.Closure),
                     find(groovy.lang.Closure),
                     min(),
                     min(groovy.lang.Closure),
                     min(java.util.Comparator),
                     size()

虽然我不清楚逻辑的完整上下文,但您可以使用
find{}
作为闭包操作获得所需内容,如下所示:

def groupsList = entity.companyContainer.groups

groupsList.each{ g ->
   g.users.each {u ->
     if(u.groups.find{it.id == g.id}) {
        u.groups.remove(g)
        entityService.update(u)
     }
   }
   entityService.delete(g)
}

为什么不工作?那么,听起来变量
u
不存在。很抱歉,前面复制了不正确的堆栈跟踪,以下是正确的oneERROR | com.core.common.controller.impl.BaseMultiActionController | groovy.lang.MissingMethodException:没有方法签名:com.core.configuration.persistence.ListWithPersistentSetPropertyAccessor$ListWithPersistentSet.find()适用于参数类型:(com.core.security.model.impl.Group)值:可能的解决方案:find(groovy.lang.Closure)、find(groovy.lang.Closure)、min()、min(groovy.lang.Closure)、min(java.util.Comparator)、size()这意味着在
groups
上没有名为
find
的方法采用
g
类型。什么样的对象是
groups
?它将以同样的方式工作,但在这种情况下,更适合任何方法而不是find。