繁体   English   中英

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

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

在我的应用程序中,我有一个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

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

正如Grails文档所述您还可以用Java编写Grails域类
你必须使用Java的org.codehaus.groovy.runtime.InvokerHelper
有关更多信息,请参阅此邮件列表
一种示例代码

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);

也许这篇文章也有帮助。
但我同意在Groovy中编写类的想法。

暂无
暂无

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

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