次の Groovy コードは Grails で動作します( @Will Pに感謝) 。
String string2code = "variable = 'hello'; return variable.toUpperCase()";
def result = new GroovyShell().evaluate string2code
assert result == "HELLO"
残念ながら、Grails の魔法のクエリを導入すると失敗します。
String string2code = "return DomainClassExample.findByName('hello')";
// String string2code = "DomainClassExample.where { name == 'hello' }"
def queryResult = new GroovyShell().evaluate string2code
これはエラーです:
Class
groovy.lang.MissingPropertyException
Message
No such property: DomainClassExample for class: Script1
出来ますか?どのように?