如何解决当ENUM字段时,Grails 4域对象失败:GET失败,因为Enum查找失败
这与我之前发布的问题有关:
从数据库中检索域类实例的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 举报,一经查实,本站将立刻删除。