2015-05-04 19 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是实际的地图。