首页 > 其他 > 详细

Grails - Domain nullable

时间:2020-04-30 10:32:05      阅读:53      评论:0      收藏:0      [点我收藏+]

Purpose

  • 允许一个 String 类型的字段被设置成 null,默认Grails不能为空。
class Domain {
    Integer id
    String url

    static constraints = {
        url nullable: true
    }
}

Description

  • 当表单的输入框没有值的时候,Web 请求提交的是 blank 字符串,而不是 null
  • 在将多个值绑定的 property 的时候需要注意这点。
  • 使用默认的配置时,系统会将 blank 转换成 null,来对应系统默认设置的 nullable: false
  • 我们可以通过如下地方修改这个默认转换行为
grails-app/conf/application.groovy
// the default value for this property is true
grails.databinding.convertEmptyStringsToNull = false

Reference

https://docs.grails.org/latest/ref/Constraints/nullable.html

Grails - Domain nullable

原文:https://www.cnblogs.com/duchaoqun/p/12807065.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!