我的控制器中无法访问域类
我是 Grails 和 groovy 的新手..
我创建了一个域类
\grails-app\domain\Abc
现在我在
\grails-app\controllers\myapp\myController
其中创建了一个控制器,当我创建一个对象时它显示错误。
def Abc obj = new Abc
我得到的错误是
unable to resolve class Abc
我尝试导入,但也没有显示在那里。我使用 grails 1.3.7 和 IntelliJ IDEA 10.0.2
谢谢
I'm new to Grails and groovy..
I created a domain class
\grails-app\domain\Abc
Now i created a controller in
\grails-app\controllers\myapp\myController
In that, when i created an object it shows error.
def Abc obj = new Abc
The error i got is
unable to resolve class Abc
I tried to import, but didn't shown there also. Me working in grails 1.3.7 and IntelliJ IDEA 10.0.2
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保每个类的位置与类和包声明一致。
这个类应该看起来像这样,
确保您没有包声明,因为根据位置,这个类应该位于默认包中(这实际上是一个不好的做法)。理想情况下,您应该将此类放入包中,然后将源文件移动到与包名称相对应的
\grails-app\domain
子目录中。这个类应该看起来像这样
请注意,这个类应该用小写的“m”命名,因为这就是文件的命名方式。标准 Java/Groovy 命名约定规定类应以大写字母开头。
此代码有几个问题:
def
或Abc
但不是两者都试试这个:
Make sure that the location of each class is consistent with the class and package declaration.
This class should look like this
make sure you have no package declaration, because based on the location, this class should be in the default package (which is actually a bad practice). Ideally you should put this class into a package, then move the source file into a subdirectory of
\grails-app\domain
that corresponds to the package name.This class should look like this
Notice that this class should be named with a lower-case 'm' because that's how the file is named. The standard Java/Groovy naming conventions dictate that classes should begin with a capital letter.
There are a couple of problems with this code:
def
orAbc
but not bothTry this instead:
我认为您创建了您的域类 &手动控制器类。首先,您的控制器应该位于
controllers
文件夹中,而不是myapp
中。其次,您应该为您的域类和域类定义一个包。控制器类,例如:领域类:
控制器类
I think you created your domain class & controller class manually. First, your controller should be in the folder
controllers
, notmyapp
. Second, you should define a package for both your domain class & controller class, for example:Domain class:
Controller class