Grails bindData由注释排除

时间:2014-04-04 19:05:37

标签: grails

我想从数据绑定中排除域字段 是否可以通过注释标记类字段?

例如域名:

class Article {
  String text
  .....
  Author author
}

在代码中我必须编写bindData(文章,参数,[排除:['作者']])作弊预防

但是更容易注释作者作者。但我没有找到。

1 个答案:

答案 0 :(得分:1)

自Grails 2.1.0起,您可以使用bindable constraint来指示在数据绑定期间不应自动分配属性。

class Article {
    String text
    ...
    Author author

    static constraints = {
        author bindable: false
    }
}

现在,调用bindData(article, params)会自动排除文章的author属性。

相关问题