Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java源代码中的Grails域类方法错误:找不到符号_Java_Grails_Groovy - Fatal编程技术网

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

java源代码中的Grails域类方法错误:找不到符号,java,grails,groovy,Java,Grails,Groovy,在我的应用程序中,我有一个grails域类学生。我在src.java中也有一些类最初是用纯java编写的 在其中一节课中,我试图以某种方式收集这样的学生: this.students = new ArrayList<Student>(Student.findAll()); this.students=newarraylist(Student.findAll()); Grails包已经导入,intellij并没有抱怨,但我在尝试编译时遇到了一个愚蠢的错误 [groovyc] org

在我的应用程序中,我有一个grails域类学生。我在src.java中也有一些类最初是用纯java编写的

在其中一节课中,我试图以某种方式收集这样的学生:

this.students = new ArrayList<Student>(Student.findAll());
this.students=newarraylist(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
[groovyc]org.codehaus.groovy.control.multipleComplationErrorsException:启动失败:
[groovyc]使用javac编译时发生编译错误。
[groovyc]F:\path\ProjectName\src\java\grb\StudentSchedule.java:58:错误:找不到符号
[groovyc]this.students=newarraylist(Student.findAll());
[groovyc]^
[groovyc]符号:方法findAll()
[groovyc]地点:班级学生
我也尝试了不同的方法,在学生身上,但都给了我相同的错误-找不到符号

状态:您还可以用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编写类的想法。

作为状态:您也可以用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中编写类的想法。

Grails将方法
findAll()
动态添加到所有域类中。因此,调用该方法依赖于Groovy的动态调度来找到该方法并执行它。由于该方法在类本身中不存在,因此不能直接从Java.Emmanuel调用它,谢谢您的评论!有什么解决方法吗?用groovy而不是Java编写这些类您使用的是哪个版本的Grails?Grails会将方法
findAll()
动态添加到所有域类中。因此,调用该方法依赖于Groovy的动态调度来找到该方法并执行它。由于该方法在类本身中不存在,因此不能直接从Java.Emmanuel调用它,谢谢您的评论!有什么解决方法吗?用groovy而不是Java编写这些类您使用的是哪个版本的Grails?谢谢Mikelis!这就是我最后所做的,而且成功了!谢谢你,米凯利斯!这就是我最后所做的,而且成功了!