1
我目前正在研究Grails应用程序。我在控制器中有两个命令对象(AccountInfoCommand和EducInfoCommand)。在我的EducInfoCommand上,我想检查yearGraduated属性是否早于set 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
}
}
请帮帮忙! 谢谢!
Im很抱歉,这个ISN没有工作。抛出空指针异常错误。 – chemilleX3
您将需要适当地填充用户名字段。为此,您应该添加一个可为null的false对象。 – krock