Constraints Usage 约束用法
Constraints provide Grails with a declarative DSL for defining validation rules, schema generation and CRUD generation meta data. An example of a set of constraints applied to a domain class are as follows:
约束为Grails提供了声明式的DSL定义,包括验证规则,schema生成(数据库相关信息的生成--译者注)和CRUD元数据的生成。比如一个领域类的约束集合如下:
class User {
... static constraints = {
login(size:5..15, blank:false, unique:true)
password(size:5..15, blank:false)
email(email:true, blank:false)
age(min:18, nullable:false)
}
} Refer to the user guide topic on Constraints for more information.
更多信息请参照用户指南约束主题。