Where should I place a transient domain class in a grails app?

血红的双手。 提交于 2019-12-04 11:17:08

问题


Where should I place a transient domain class in a grails app?

Ie I have an Action class that will be passed about, and used, but never saved. Should this be in the grails-app/domain folder, or somewhere else?


回答1:


grails-app/domain is for persistent domain classes, but not all of your application's domain-related classes need to be there, e.g. in this case where you want to use it as a value object. You can put these in src/groovy along with other classes that aren't considered Grails artifacts.

If you want the classes to support validation, you can annotate them with @Validateable - see section "7.5 Validation Non Domain and Command Object Classes" in the ref docs: http://grails.org/doc/latest/




回答2:


I think a CommandObject may fit the bill. These typically go in the same directory as your controllers, have the same validation features available to domain objects, but are never persisted. Great for things like search forms.



来源:https://stackoverflow.com/questions/5051720/where-should-i-place-a-transient-domain-class-in-a-grails-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!