在我的 Grails 域类中,我想设置在数据库中保留的默认值。我使用mysql作为数据库。我试图这样做:
class A {
long someValue = 1
long someOtherValue
boolean someBool = true
boolean someOtherBool
static mapping = {
someOtherValue defaultValue: 1
someOtherBool defaultValue: true
}
}
但没有任何作用。数据库中没有设置默认值。我必须更改什么才能正确设置我的默认值?
最佳答案
如果你在 Grails 2.2 以上,那么你可以使用 defaultValue。看看伯特的回答 here
试试看,希望这有帮助:
Class A {
Long someValue
Long someOtherValue
Boolean someBool
Boolean someOtherBool
static mapping = {
someOtherValue defaultValue: 1
someOtherBool defaultValue: true
...
}
}
关于grails - 如何在 Grails 2.2 中设置域类值的默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16505968/