2015-05-04 21 views
1

試圖回答一個快速問題,沒有任何運氣在線搜索。Groovy空格分隔的散列圖鍵

我學習Groovy和跨越此代碼段上線了:

class Person { 
    String name 
    Person parent 
    static belongsTo = [ supervisor: Person ] 

    static mappedBy = [ supervisor: "none", parent: "none" ] 

    static constraints = { supervisor nullable: true } 
} 

我特別關心Person類體的最後一行。 { supervisor nullable: true }是什麼意思?那些鏈接到價值true什麼的多個鍵?

謝謝!

回答

4

這是短於:

static constraints = { 
    supervisor([nullable: true]) 
} 

然後意味着:定義名爲constraints類變量,其保持閉合(封閉件在常規第一類數據)。閉包(稍後調用時)將執行其中的代碼。

代碼中有一個DSL用於配置後面數據庫抽象的約束條件。所以supervisor是一個方法調用(該方法不存在,但DSL的委託負責)。 The () maybe left out, if "unambiguous"。接下來,如果方法採用Map作爲參數,那麼也可以省略[]

請注意,belongsTomappedBy是實際的地圖。