在完成问题https://jira.grails.org/browse/GPMONGODB-232后,我对将枚举类型保存为序数值有错误的印象,我们现在可以使用自定义 ID 保存枚举。
例如:
这不会保存值为 2 或 3 的字段类型。
package test
class User {
static mapping = {
//type enumType: "ordinal"
}
UserType type
String name
}
enum UserType {
A(2),
B(3),
int getId() {
this.id
}
final int id
UserType(int id) {
this.id = id
}
}
我们如何在安装了 mongodb 插件的 grails 应用程序中保存带有自定义 id 的枚举(如上所示)?