Java中的inList约束
我正在将一个应用程序从Grails转换为Java,需要找到Grails中inList约束与spring/hibernate约束的等价物Java中的inList约束,java,spring,hibernate,grails,Java,Spring,Hibernate,Grails,我正在将一个应用程序从Grails转换为Java,需要找到Grails中inList约束与spring/hibernate约束的等价物 static constraints = { stringValue(inList:['testValue', 'testValue', 'testValue', 'testValue', 'test value', 'test&value'], nullable:false) } 我不确定hibernate/sprin
static constraints = {
stringValue(inList:['testValue', 'testValue', 'testValue', 'testValue', 'test value', 'test&value'], nullable:false)
}
我不确定hibernate/spring对于这种类型的约束是什么
更新
我尝试使用枚举,但我需要包括特殊字符,如&和空格,因此据我所知,只有字符串可以工作,因为我必须从数据库中提取这些值。我认为没有内置约束,但您可以自己编写。为什么不使用枚举而不是字符串呢?如前所述,枚举可以完成这项工作。或者在Hibernate中使用集合。如果要将变量设置为枚举,请使用属性转换器将枚举转换为字符串,反之亦然。谷歌搜索“JPA属性转换器”