来自java源码的Grails域类方法错误:找不到符号

时间:2016-04-24 14:18:17

标签: java grails groovy

在我的应用程序中,我有一个grails域类Student。我在src.java中也有一些最初用普通java编写的类。

在某些方法的其中一个课程中,我试图得到像这样的学生集合:

this.students = new ArrayList<Student>(Student.findAll());

导入Grails包,intellij没有抱怨,但是在尝试编译时我遇到了愚蠢的错误。

[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
  [groovyc] Compile error during compilation with javac.
  [groovyc] F:\path\ProjectName\src\java\grb\StudentSchedule.java:58: error: cannot find symbol
  [groovyc]         this.students = new ArrayList<Student>(Student.findAll());
  [groovyc]                                                       ^
  [groovyc]   symbol:   method findAll()
  [groovyc]   location: class Student

我一直在尝试不同的方法,对学生,但所有给我同样的错误 - 找不到符号。

1 个答案:

答案 0 :(得分:3)

作为Grails docs状态: 您还可以用Java编写Grails域类
您必须使用Java中的 org.codehaus.groovy.runtime.InvokerHelper 有关详细信息,请参阅此mailing list
一种示例代码

{{1}}

也许this post也可以提供帮助。
但我同意在Groovy中编写类的想法。