class Book {
String title
Author author
static constraints = {
title blank: false, size: 5..150
author nullable: true
}
}
約束
目的
允許定義宣告式驗證約束。請參閱使用者指南中的驗證。
範例
說明
def b = new Book()
assert !b.validate()
靜態 constrainedProperties
屬性是 Map,其中 Map 中的鍵是屬性名稱,而與鍵關聯的值是ConstrainedProperty的執行個體
def constraintsMap = Book.constrainedProperties
for(entry in constraintsMap) {
// propertyName is a String
def propertyName = entry.key
// constrainedProperty is a ConstrainedProperty
def constrainedProperty = entry.value
// ...
}