我有一堂课:
class PersonCommand implements Validateable {
String firstName
String lastName
static constraints = {
firstName nullable: true
lastName nullable: true
}
}
我有一个我需要验证的 PersonCommand 类型的列表。我想遍历每个元素并检查 firstName 和 lastName 是否都为空。有没有办法在不明确检查这些属性的情况下做到这一点?我想做类似的事情:
for(PersonCommand person in people) {
if(areAllMapValuesNull(person.properties)) {
person.validate()
} else {
...
但是 person.properties 添加了其他属性,而不仅仅是 firstName 和 lastName,因为它是 Validateable。我不是在寻求有关 areAllMapValuesNull() 函数的帮助,只是在获取值 firstName 和 lastName 而不对检查进行硬编码。