我目前正在开发一个 grails 应用程序。我在控制器中有两个命令对象(AccountInfoCommand 和 EducInfoCommand)。在我的 EducInfoCommand 上,我想检查 yearGraduated 属性是否早于其验证器约束中设置的birthDate(AccountInfoCommand 的属性)。我将如何做到这一点?
这是我的 AccountInfoCommand 代码:
class AccountDetailsCommand implements java.io.Serializable {
String username
String password
String confirmPassword
String emailAddress
Date birthDate
}
这是我的 EducInfoCommand 代码:
class EducInfoCommand implements java.io.Serializable {
Integer graduated
EducationLevel educationLevel
String schoolName
String yearGraduated
String honorsReceived
}
static constraints = {
yearGraduated nullable: false, maxSize:4, blank: false, matches: /([0-9]*)/,
validator: {
Date.parse('yyyy',it) <= new Date() ? true : false
}
}
请帮忙!谢谢!