0
class Book {

String name
String author       
 static constraints = { name(nullable:true) 
}
}

以上似乎有效,但是当我为多个字段设置约束时,服务器无法启动

class Book {

String name
String author       
 static constraints = { name(nullable:true) author(nullabe:false)
}
}

使用上面的代码......我得到以下异常

原因:groovy.lang.MissingMethodException:没有方法签名:org.codehaus.groovy.grails.validation.ConstrainedProperty.call() 适用于参数类型:(org.codehaus.groovy.grails.validation.ConstrainedProperty) 值: [org.codehau s.groovy.grails.validation.ConstrainedProperty@3343e5[class com.nthdimenzion.domain.Book,author,class java.lang.String,{nulla ble=org.codehaus.groovy.grails.validation.NullableConstraint @1aea6e2[false]}]] 可能的解决方案:wait(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure), isUrl() at com.nthdimenzion。 domain.Book$_ clinit _closure1.doCall(Book.groovy:16) at com.nthdimenzion.domain.Book$_ clinit _closure1.doCall(Book.groovy) ... 23 更多

有任何想法吗 ?

4

1 回答 1

4

这是因为你在同一行...

尝试

 static constraints = { 
    name(nullable:true) 
    author(nullabe:false)
 }

编辑:

您也可以将条目分开,;然后如果您想要的话,您可以将它们全部放在一行上。(但我认为我们大多数人不使用oneliners......)

于 2011-05-10T08:31:35.570 回答