[英]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.