Grails 域类对字段之间关系的约束
我需要在 Grails 中编写 Domain 类约束,它表示一个整数字段必须大于或等于另一个。
当我编写这样的代码时:
class MyDomain {
String title
int valueMin = 1
int valueMax = 1
static constraints = {
valueMin(min:1)
valueMax(min:valueMin)
}
}
我收到错误:
Caused by: groovy.lang.MissingPropertyException: No such property: valueMin for class: MyDomain
请问有什么想法吗?
I need to write Domain class constraint in Grails which says that one integer field must be greater or equal than the other.
When I write the code like this:
class MyDomain {
String title
int valueMin = 1
int valueMax = 1
static constraints = {
valueMin(min:1)
valueMax(min:valueMin)
}
}
I'm getting error:
Caused by: groovy.lang.MissingPropertyException: No such property: valueMin for class: MyDomain
Any idea, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://grails.org/doc/latest/ref/Constraints/validator.html
这或多或少应该有效(未经测试)
http://grails.org/doc/latest/ref/Constraints/validator.html
This should more or less work (not tested)
这是行不通的,因为约束是静态代码块,只能访问静态变量。
因此,如果您愿意,您可以编写自己的自定义约束:看看这个链接:
http://grails.org/doc/latest/guide/single.html# 7.。验证
This wont work, because the constraints are a static block of code which will only have access to static variables.
So, you could write your own customized cosntraint if you want: take a look at this link:
http://grails.org/doc/latest/guide/single.html#7. Validation