自定义简单约束grails [英] custom simple constraint grails

查看:292
本文介绍了自定义简单约束grails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个自定义简单约束(如显示和可编辑),我可以在我的域类中使用。是否可以扩展ConstrainedProperty类?

I would like to create a custom simple constraint (like display and editable) which I can use within my Domain class. Is it possible to extend ConstrainedProperty class?

class City {
    String title
    BigDecimal latitude
    BigDecimal longitude
    Country country

    static constraints = {
        title       ( blank: false, customConstraint: true )  // filter can be also be applied as attributes: [customConstraint: true]
    }
}

有人熟悉这种情况吗?

推荐答案

要创建自己的约束:

  • extend org.codehaus.groovy.grails.validation.AbstractConstraint
  • register the class as a constraint by calling org.codehaus.groovy.grails.validation.ConstrainedProperty.registerNewConstraint

查看 grails实现大小约束例如。

这篇关于自定义简单约束grails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆