(快速參考)

max

目的

確保值不會超過最大值。

範例

age max: new Date()
price max: 999F

說明

設定實作 java.lang.Comparable 的類別的最大值。值的類型必須與屬性相同。

請注意,約束只會評估一次,這可能與依賴於值(例如 java.util.Date 的實例)的約束有關。

class User {
    ...

    static constraints = {
        // this Date object is created when the constraints are evaluated, not
        // each time an instance of the User class is validated.
        birthDate max: new Date()
    }
}

此約束會影響 Schema 產生

錯誤代碼:className.propertyName.max.exceeded