我是新手,试图根据嵌入式类的日期字段获取域列表。
以下工作正常
def res = User.findAll { lt 'createdDateTime', new Date }
def res = User.findAll { eq 'account.name', 'JOHN' }
但,
def res = User.findAll { lt 'account.createdDateTime', new Date }
上面总是返回空列表。
“帐户”类已嵌入到“用户”类中
User.groovy
class User {
String name
Integer age
Date ctratedDateTime // test
Account account
static embedded = [
'account'
]
}
Account.groovy
class Account {
String userName
String password
Date createdDateTime
}
def res = User.findAll {
account{
lt 'createdDateTime', new Date
}
}
对于上面得到以下错误
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [list] of controller [com.test.UserController] caused exception: Runtime error executing action
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Runtime error executing action
... 5 more
Caused by: java.lang.reflect.InvocationTargetException
... 5 more
Caused by: java.lang.NoSuchMethodError: com.test.UserController$_getFilteredForexRates_closure9.<init>(Ljava/lang/Object;Ljava/lang/Object;Lgroovy/lang/Reference;)V
at com.test.UserController$$EOqgV3Um.getFilteredForexRates(UserController.groovy:172)
at com.test.UserController$_closure5$$EOqgV3Um.doCall(UserController.groovy:109)
... 5 more
我做的正确吗?请给我建议解决方法。
谢谢。
最佳答案
您应该使用嵌套的闭包:
def res = User.withCriteria{
account{
lt 'createdDateTime', new Date
}
}
关于grails - 基于嵌入式日期字段的Grais列表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25991303/