(快速參考)

bindable

目的

設定屬性的可繫結性。

範例

salary bindable: false
firstName size: 5..15, bindable: true
department bindable: true

說明

設定為 false 表示屬性不得在資料繫結期間自動指派值。

package com.demo

class Employee {
    String firstName
    String department
    BigDecimal salary

    static constraints = {
        department bindable: false
        salary bindable: false
    }
}
import com.demo.Employee

def employee = new Employee()
employee.firstName = 'Bill'
employee.department = 'Percussion'
employee.salary = 42.0

// department and salary will NOT be bound because they are configured as non-bindable in the Employee.constraints closure
employee.properties = [firstName: 'William',
                       department: 'Retired',
                       salary: 99.99]

assert 'William' == employee.firstName
assert 'Percussion' == employee.department
assert 42.0 == employee.salary

靜態型別的實例屬性預設為可繫結。預設不可繫結的屬性包括與暫時欄位、動態型別屬性和靜態屬性相關的屬性。

請參閱 資料繫結 區段,深入瞭解資料繫結。

bindable 約束必須指派一個文字布林值。動態表達式不是 bindable 約束的有效值。值必須是文字 truefalse

bindable 約束必須套用在相關類別中定義的約束封閉中。這表示 bindable 不得用作共用約束。