简体   繁体   English

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

[英]Grails domain class method from java source error: cannot find symbol

In my app I have a grails domain class Student. 在我的应用程序中,我有一个grails域类Student。 I also have a few classes in src.java originally written in plain java. 我在src.java中也有一些最初用普通java编写的类。

In one of those classes in some method I am trying to get a collection of students like this: 在某些方法中的其中一个类中,我试图得到这样的学生集合:

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

Grails package is imported, intellij doesn't complain, however I get foolwing error while trying to compile. 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

I have been also trying different methods, on Student, but all give me the same error - cannot find symbol. 我一直在尝试不同的方法,对学生,但所有给我同样的错误 - 找不到符号。

As the Grails docs state: You can also write Grails domain classes in Java 正如Grails文档所述您还可以用Java编写Grails域类
You have to use org.codehaus.groovy.runtime.InvokerHelper from Java 你必须使用Java的org.codehaus.groovy.runtime.InvokerHelper
For more information see this mailing list 有关更多信息,请参阅此邮件列表
Kind of sample code : 一种示例代码

import my.package.User
import org.codehaus.groovy.runtime.InvokerHelper;

List allInstances = (List)InvokerHelper.invokeMethod(User.class, "list", null)); 

User one=(User)InvokerHelper.invokeMethod(User.class, "get", id);

maybe this post can help as well. 也许这篇文章也有帮助。
But I would agree on the idea of writing the classes in Groovy. 但我同意在Groovy中编写类的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM