问题描述
这与我之前发布的问题有关:
从数据库中检索域类实例的GET请求失败,因为对ENUM字段的查找失败,并出现以下错误:
处理请求:[GET] / domainObject / show / 1时发生IllegalArgumentException 没有枚举常量com.project.core.dsl.Category。
Enum
类:
package com.project.core.dsl
import groovy.transform.CompileStatic
@CompileStatic
enum Category {
CATEGORY_ONE("Category One"),CATEGORY_TWO("Category Two"),CATEGORY_THREE("Category Three")
private final String id
private Category(String id) { this.id = id }
@Override
String toString() { id }
String getKey() { name() }
}
域类:
package com.project.core
import com.project.core.dsl.someOtherEnum
import com.project.core.dsl.Category
class DomainObject {
SomeOtherEnum someOtherEnum
Set<Category> categories
static hasMany = [categories: Category]
static constraints = {
}
static mapping = {
someOtherEnum index: true
}
@Override
String toString() {
return "DomainObject{" +
"someOtherEnum=" + someOtherEnum +
",categories=" + categories +
'}';
}
}
数据库记录存储categories
字段的值,如下所示:
"categories" : [ "Category One","Category Two" ]
我怀疑查找失败,因为valueOf无法通过使用id
的{{1}}值来找到枚举。要使此查找工作,我需要更改什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)