Grails默认包名称 [英] Grails default package name
问题描述
org.company.project.module.model
这样的包中。对我来说,重复 create-domain-class< package>。< class_name>
是相当痛苦的。有没有像包模板或我可以以某种方式输入(如 grails cd org.comopany ...
),然后只写类名( grails Person
将在 ./
位置中生成)?这是可能的,还是应该使用复制粘贴
设计模式? 感谢您提供任何帮助。
如果我理解了您的问题,你的域类。在你的 config.groovy
文件中有一行说:
grails .project.groupId = appName
如果您给它一个appName,Grails将使用它作为默认包名称,当它产生的文物。
grails.project.groupId ='com.example.yourpackagename'
如果您现在默认创建一个域类,它将在 com / example / yourpackagename
下找到它。
更新
不需要使用Grails命令,如create-domain类或其他命令来创建工件。这些都只是您可以手动创建的类。只需创建一个文件并将其复制到同一个包中即可。
更新
Grails交互模式(键入grails时)通过按 tab
命令,它将在包名称的唯一部分之前输入。
UPDATE for Grails 3.0
这个设置已经进入 conf / application.yml
:
grails:
配置文件:web
codegen:
defaultPackage:com.example.yourpackagename
I am new to Grails and I like it very much. I want to place my classes in packages like org.company.project.module.model
. Its quite painful for to me to repeat create-domain-class <package>.<class_name>
. Is there something like "package templates" or can I somehow "enter" (like grails cd org.comopany...
) and then just write Class names (grails Person
will be generated in ./
location)? Is that possible or should I use copy paste
design pattern?
Thanks in advance for any help.
If I understood your question, you are looking for default package name for your domain classes. In your config.groovy
file there is a line saying:
grails.project.groupId = appName
if you give it an appName, Grails will use that as the default package name when it generates the artifacts.
grails.project.groupId = 'com.example.yourpackagename'
If you now create a domain class by default it will locate it under com/example/yourpackagename
.
UPDATE
It is not required to use Grails commands like create-domain-class or other commands to create artifacts. These are all just classes that you can manually create. Just create a file and duplicate it in the same package.
UPDATE
Grails interactive mode (when you type grails) for some of the commands by pressing tab
it will type ahead the unique portion of the package name.
UPDATE for Grails 3.0
The setting has moved into conf/application.yml
:
grails:
profile: web
codegen:
defaultPackage: com.example.yourpackagename
这篇关于Grails默认包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!