获取字段值
Get the value of the field
有个class
class Real {
static constraints = {
param_name()
param_descr()
param_type(inList: ["val",
"symbol",
"string",
"Boolean",
])
}
String param_name
String param_descr
String param_type
}
我可以获取 param_type 值吗?
如果是,怎么做?
我需要我的 isList 值来进一步工作
嗯,还是可以用其他方式来做?
朋友,我认为你误解了 grails 或 groovy 中的约束。
"Constraints provide Grails with a declarative DSL for defining validation rules, schema generation and CRUD generation meta data"。
例如,考虑这些约束:
class 用户 {
...
static constraints = {
login size: 5..15, blank: false, unique: true
password size: 5..15, blank: false
email email: true, blank: false
age min: 18
}
}
inlist的使用是:
验证值是否在约束值的范围或集合内。
例如:name(inList: ["Joe", "Fred", "Bob"])
在您的场景中,您验证了您在 inList 中给出的约束值集合中的 param_type 值。
更多信息,请参考以下grails官方页面
https://docs.grails.org/latest/ref/Constraints/Usage.html
如果我误解了你的问题请评论我。
我相信在 grails 3 中你会像这样访问这个值列表:
Real.getConstrainedProperties().param_type.inList
在 grails 2 中这只是
Real.constraints.param_type.inList
这将 return 您可以在 <g:select>
中使用的值列表,例如
<g:select id="theType" from="${Real.getConstrainedProperties().param_type.inList}"/>
有个class
class Real {
static constraints = {
param_name()
param_descr()
param_type(inList: ["val",
"symbol",
"string",
"Boolean",
])
}
String param_name
String param_descr
String param_type
}
我可以获取 param_type 值吗?
如果是,怎么做?
我需要我的 isList 值来进一步工作
嗯,还是可以用其他方式来做?
朋友,我认为你误解了 grails 或 groovy 中的约束。
"Constraints provide Grails with a declarative DSL for defining validation rules, schema generation and CRUD generation meta data"。 例如,考虑这些约束:
class 用户 { ...
static constraints = {
login size: 5..15, blank: false, unique: true
password size: 5..15, blank: false
email email: true, blank: false
age min: 18
}
}
inlist的使用是: 验证值是否在约束值的范围或集合内。 例如:name(inList: ["Joe", "Fred", "Bob"])
在您的场景中,您验证了您在 inList 中给出的约束值集合中的 param_type 值。
更多信息,请参考以下grails官方页面 https://docs.grails.org/latest/ref/Constraints/Usage.html
如果我误解了你的问题请评论我。
我相信在 grails 3 中你会像这样访问这个值列表:
Real.getConstrainedProperties().param_type.inList
在 grails 2 中这只是
Real.constraints.param_type.inList
这将 return 您可以在 <g:select>
中使用的值列表,例如
<g:select id="theType" from="${Real.getConstrainedProperties().param_type.inList}"/>