【发布时间】:2016-04-24 14:18:16
【问题描述】:
在我的应用程序中,我有一个 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
我也一直在尝试不同的方法,在 Student 上,但都给我同样的错误 - 找不到符号。
【问题讨论】:
-
方法
findAll()由Grails 动态添加到所有域类中。所以调用方法依赖于 Groovy 的动态调度来找到方法然后执行。因为类本身不存在该方法,所以不能直接从Java中调用。 -
伊曼纽尔,感谢您的评论!有什么办法可以解决吗?
-
用 groovy 而不是 Java 编写这些类
-
您使用的是哪个版本的 Grails?