grails 约束用法

约束为Grails提供了声明式的DSL定义,包括验证规则,schema生成和CRUD元数据的生成。

1.blank

验证一个String值是否为空。

login(blank:false)

2.creditCard

验证一个String值是否为credit card number

3.email

验证是否为有效的邮件地址

4.inList

验证所给的值是否在所给的集合中。

name(inList:["Joe", "Fred", "Bob"] )

5.matches

正规表达式验证

6.max

最大值限制

7.maxSize

大小限制

8.min/minSize

9.notEqual

不能等于指定值

10.nullable

11.range

在指定范围内

12.scale

指定小数位数

13.size

 

children(size:5..15)

14.unique

数据库级唯一。

Be aware that it's possible (though uncommon in practice) for a uniqueness constraint validation to pass but a subsequent save of the data to fail due to a uniqueness constraint enforced at the database level. The only way to prevent this would be to use the SERIALIZABLE transaction isolation level (bad for performance) or just be prepared to get an exception to this effect at some point.

15.url

URL格式验证

16.validator

自定义验证。

 

最后欢迎大家访问我的个人网站:1024s​​​​​​​

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值