4

我刚开始学习 Grails,我正在尝试使用 grails 控制台来玩数据库,但我注意到 runninggrails console和 running之间存在差异grails,然后console

grails console直接从终端启动时:

~/Desktop/Grails-lab/racetrack $ grails console
| Compiling 1 source files.....

console

groovy> import racetrack.* 
groovy> def z = new User(userName:"bangkuangwang",fullName:"noge noge",website:"noge.com",email:"email@email.com",bio:"hello world",password:"123123") 
groovy> z.save() 
groovy> println(z.errors) 
groovy> User.count 

grails.validation.ValidationErrors: 0 errors

Result: 1

使用 启动时grails,然后console

~/Desktop/Grails-lab/racetrack $ grails
| Enter a script name to run. Use TAB for completion: 
grails> console
| Compiling 1 source files.....

console

groovy> import racetrack.* 
groovy> def z = new User(userName:"bangkuangwang",fullName:"noge noge",website:"noge.com",email:"email@email.com",bio:"hello world",password:"123123") 
groovy> z.save() 
groovy> println(z.errors) 
groovy> User.count 

Exception thrown

groovy.lang.MissingMethodException: No signature of method: racetrack.User.save() is applicable for argument types: () values: []
Possible solutions: save(), save(boolean), save(java.util.Map), wait(), last(), any()
at com.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:963)
at racetrack.User.save(User.groovy)
at racetrack.User$save.call(Unknown Source)
at ConsoleScript0.run(ConsoleScript0:3)
at com.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1231)
at com.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1231)

谁能向我解释为什么启动 grails 控制台的两种方法的行为不同?

4

1 回答 1

0

看起来像一个错误。我建议您坚持使用“grails 控制台”。

于 2012-11-16T02:34:05.393 回答