1

永続化を必要としない grails ドメイン オブジェクトと同様のオブジェクトが必要です。フィールドを変更するために 2 つの場所を変更する必要がないようにするために、ドメイン クラスを拡張して、単一のフィールド セットの利点を得ることができるようにすることをお勧めします。ただし、関連するすべてのオブジェクトとコレクションをやり直す必要があります。

4

1 に答える 1

2

@cfrickはスポットです。Groovy トレイトは非常に優れた方法です。ここで完全な例を取得できます(プロジェクトの名前が悪いことは知っています)。簡単な例を次に示します。

// MyTrain.groovy: Put this in src/main/groovy/my/package
package my.package

trait MyTrait {
    Integer number
    String something
}

// MyDomainClass.groovy: This goes with the other domain classes.
package my.package

class MyDomainClass implements MyTrait {
    /*  
     * number and something properties are available here.
     * They become table columns.
     */  

    static constraints {
        /*  
         * And you can place constraints on them,
         * as it they had been declared in this class.
         */  
    }   
}
于 2016-01-06T15:15:22.283 に答える