0

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

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

谢谢!

4

2 回答 2

1

使用“beforeInsert”来处理转换。

def beforeInsert() {
    boolField = (boolField=='S')?true:false
}
于 2014-06-16T03:06:02.953 回答
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'
}
于 2016-09-27T12:41:28.480 回答