0

不知道我在这里错过了什么,恐怕它是愚蠢的。非常简单的设置,我发布/reference/save并没有传递任何东西......期望得到一个required error. 文档状态,nullable:true默认情况下但我开始认为那是不正确的。

#domain
class Reference{
    String name;
    String publication;
    String year;
    String section;
    String description;
    String link;
    static constraints = {
        year nullable: true
        section nullable: true
        link url: true
    }   
}

#controller:
Reference referenceInstance = new Reference(params)
println(params)
println(referenceInstance.validate())

输出:

>>[description:, link:, name:, year:, section:, publication:, action:save, controller:reference]
>>true
4

1 回答 1

3

尝试将blank约束添加到您的属性中。

您的参数映射包含每个属性的键。Grails 将它们视为空字符串,而不是null.

static constraints = {
    year nullable: true
    section nullable: true
    link url: true, blank: false
    description blank: false
    name blank: false
    publication blank: false
}
于 2013-02-26T21:24:05.543 回答