【问题标题】:Mapping CHAR oracle type to Boolean in Gorm在 Gorm 中将 CHAR oracle 类型映射到布尔值
【发布时间】:2014-06-15 06:30:58
【问题描述】:

我在 oracle 数据库中有一个 Char 字段。可能的值是“S”和“N”

如何将值映射到 Grails 域对象中定义的布尔字段? “S”值为真,“N”值为假。

谢谢!

【问题讨论】:

  • 你能告诉我们你到目前为止所做的尝试吗?

标签: oracle10g grails-orm grails-2.3


【解决方案1】:

在 Grails 2.5.3 中

对于“Y”值为真,“N”值为假。

static mapping = {
    boolField column: 'BOOLEAN_FLAG'
    boolField type: 'yes_no'
}

对于1值为真,0值为假。

static mapping = {
    boolField column: 'BOOLEAN_FLAG'
    boolField type: 'org.hibernate.type.NumericBooleanType'
}

【讨论】:

    【解决方案2】:

    使用“beforeInsert”来处理转换。

    def beforeInsert() {
        boolField = (boolField=='S')?true:false
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      • 2019-06-09
      • 2015-02-24
      • 2021-01-16
      • 2019-07-03
      • 1970-01-01
      • 2014-11-27
      相关资源
      最近更新 更多