如何使用包名来区分grails中的类? [英] How to use the package name to differentiate between classes in grails?

查看:88
本文介绍了如何使用包名来区分grails中的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以使用包名来区分grails中的类吗?

例如。 com.business.appName.DomainClass和com.business.appName.foo.DomainClass?

我认为这会导致问题,因为grails需要唯一的类名称。如果您尝试了这一点,当您尝试为com.business.appName.foo.DomainClass生成视图时,它会尝试覆盖com.business.appName.DomainClass的视图gsps。



有没有办法在不同的包中拥有相同的域名类?

解决方案

问题是,控制器名称必须是独一无二的。在不同包中为两个具有相同名称的域类运行'generate-controller'或'generate-all'会在它自己的包中创建两个不同的控制器,但它们都映射到/ yourapp / domainClass URL并且都将共享grails-app / views / domainClass GSP文件夹。



您需要重命名其中一个控制器,因为即使在同一个名称中也不能有两个不同的软件包,即使在URLMappings中也不能解决这个问题,所以如果你想使用生成的代码,看起来像你最好的选择就是生成第一组并移动控制器和视图,然后生成第二组。然后重命名一个或两个控制器,以便它们具有唯一的URL并重命名相应的GSP文件夹。


Can you use the package name to differentiate between classes in grails?

e.g. com.business.appName.DomainClass and com.business.appName.foo.DomainClass?

I think that this causes problems as grails needs unique class names. If you try this out it tries to overwrite the view gsps for the com.business.appName.DomainClass when you try to generate the views for the com.business.appName.foo.DomainClass

Is there a way to have the same domain class name in different packages?

解决方案

The problem is that controller names have to be unique. Running 'generate-controller' or 'generate-all' for the two domain classes with the same name in different packages creates two different controllers each in its own package, but they'll both map to /yourapp/domainClass URLs and will both share the grails-app/views/domainClass GSP folder.

You'll need to rename one of the controllers anyway since you can't have two with the same name even in different packages and can't fix this even in URLMappings, so it looks like your best bet if you want to use the generated code is to generate the first set and move the controller and views out of the way, then generate the second set. Then rename one or both of the controllers so they'll have unique URLs and rename the corresponding GSP folders.

这篇关于如何使用包名来区分grails中的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆