如何修复 "No signature of method: java.util.ArrayList.delete()" 删除对象?

How to fix "No signature of method: java.util.ArrayList.delete()" to delete a object?

我是 grails 的新手,我正在尝试删除我正在获取的所有对象 (ArrayList)。

这是获取数据的方法,有效:

def authRequest = User.findAllByExpiresLessThan(currentDate)

这就是我想要做的:

if(authRequest){
    authRequest.delete()
}

这是错误:

Caused by: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.delete() is applicable for argument types: () values: []
Possible solutions: sleep(long), sleep(long, groovy.lang.Closure), clear(), clear(), clear(), clone()

提前致谢。

如果只有 1 个对象,

authRequest.delete() 会起作用。

当您使用findAllBy instead of findBy, it will return an array of objects, instead of just one. In that case you can use "Spread" operator*.)将它们全部删除时:

authRequest*.delete()

我会使用 HQL 以原子方式删除所有对象,使用单个 (SQL DELETE) 语句

User.executeUpdate('delete User where expires < ?', [currentDate])