Grails 3使用动态类名查询

时间:2017-07-10 16:34:50

标签: grails gorm detachedcriteria

想知道为什么“where”查询在下面的最后一个例子中失败了。情况#5中的where查询没有“where”子句 - 列出所有分配而不是一个。我正在Grails控制台Grails 3.2.5中执行它。

import org.grails.compiler.injection.GrailsAwareClassLoader

def domainName = "Assignment"
def domainPathName = "somepath.$domainName"

def domainClass = new GrailsAwareClassLoader().loadClass(domainPathName)

println "1 -----------"
def c = domainClass.createCriteria()
println c.list { 
    eq "id", 9361L
}

println "2 -----------"
def wc = domainClass.withCriteria() {
    eq "id", 9361L
}
println wc.toList()

println "3 -----------"
def d = new DetachedCriteria(domainClass).build {
    eq "id", 9361L
}
println d.list() 

println "4 -----------"
def wa = Assignment.where {
 id == 9361L
}
println wa.list()

println "5 -----------"
def w = domainClass.where {
 id == 9361L
}
println w.list()

0 个答案:

没有答案