开发者

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

开发者 https://www.devze.com 2023-02-11 05:59 出处:网络
Where should I place a transient domain class in a grails app? Ie I have an Action class t开发者_JAVA百科hat will be passed about, and used, but never saved.Should this be in the grails-app/domain fo

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

Ie I have an Action class t开发者_JAVA百科hat will be passed about, and used, but never saved. Should this be in the grails-app/domain folder, or somewhere else?


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/


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消