如何在grails中保存对象
我有Grails2.0.4应用程序,我有如下新的域类,它包含大约50个属性如何在grails中保存对象,grails,grails-2.0.4,Grails,Grails 2.0.4,我有Grails2.0.4应用程序,我有如下新的域类,它包含大约50个属性 class Test{ int testField1 int testField2 int testField2 . . int testFieldN } 我想做如下工作 Display Value Value to Save in DB 'Excellent' 10 'Good' 8 'Average'
class Test{
int testField1
int testField2
int testField2
.
.
int testFieldN
}
我想做如下工作
Display Value Value to Save in DB
'Excellent' 10
'Good' 8
'Average' 6
'Poor' 4
'Pathetic' 2
我有一个包含所有这些属性的html表单
如果testField1值是“显示值”的任何值,则要保存的值将是“保存在DB中的值”中列出的相应值
例如如果testField1的值为“优秀”,则要保存的值为10
此特定映射适用于域类中大约30个属性
像这样,对于不同的属性,我有不同的映射
如何在grails中实现这一点。我建议使用枚举
class Test{
enum Scales{
Excellent(10), Good(8), Average(6), Poor(4), Pathetic(2)
private final int value
Scales(int v){ this.value = v}
int getValue(){ this.value}
}
int testField1
int testField2
int testField2
.
.
int testFieldN
}
普惠制
<g:select name='testField1' from="${Test.Scales}" optionKey="value"/>
<g:select name='testField1' from="${Test.Scales}"/>
然后
普惠制
<g:select name='testField1' from="${Test.Scales}" optionKey="value"/>
<g:select name='testField1' from="${Test.Scales}"/>