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