提问人:injecteer 提问时间:10/16/2023 更新时间:10/16/2023 访问量:20
GORM 独立版:获取所有域的约束
GORM standalone: get all Domain's constraints
问:
我在我的应用程序中使用 GORM-Stanalone:
dependencies {
api 'org.grails:grails-datastore-gorm-hibernate5:8.0.1'
// api 'org.grails:grails-validation:3.3.16' // <- tried that with no effect
}
我有一个域类,如下所示:
@Entity
class User implements GormEntity<User> {
// yada yadda
static constraints = {
name blank:false, matches:/(\p{L}+\s?)+/
password validator:{ passwordValidator.validate it }
email unique:true
permissionMask min:1
birthDate validator:{
Date now = new Date()
now - 130 * 365 < it && it < now - 10 * 365
}
address nullable:true
}
}
现在,我想获取受约束属性的列表。
我尝试遵循另一个答案,但代码
User.getConstraints()
//or
User.constraints
返回一个闭包
{"delegate":null,"owner":"vx.demo.domain2.User","thisObject":"vx.demo.domain2.User",
"resolveStrategy":3,"directive":0,"parameterTypes":["java.lang.Object"],"maximumNumberOfParameters":1}
和像这样的电话
User.getConstraints().containsKey 'name'
也失败:
groovy.lang.MissingMethodException: No signature of method: vx.demo.domain2.User$__clinit__closure5.containsKey() is applicable for argument types: (String) values: [name]
电话
User.constraints.name
结果
java.lang.NullPointerException: Cannot get property 'name' on null object
我做错了什么? 如何获取所有受约束道具名称的列表?
答: 暂无答案
评论