Grails错误类[{1}]的属性[{0}]不能为null - 在基本的grails应用程序上

时间:2013-04-25 18:09:32

标签: grails grails-2.0

这是我的简单域类:

package projectmanagement

class Project {

    String Name

    static constraints = {
    }
}

在Controller上保存方法(使用脚手架生成):

def save() {
    def projectInstance = new Project(params)
    if (!projectInstance.save(flush: true)) {
            projectInstance.errors.allErrors.each {
                println it
            }
        render(view: "create", model: [projectInstance: projectInstance])
        return
    }

    flash.message = message(code: 'default.created.message', args: [message(code: 'project.label', default: 'Project'), projectInstance.id])
    redirect(action: "show", id: projectInstance.id)
}

当我尝试保存项目时,出现以下错误:

 Field error in object 'projectmanagement.Project' on field 'name': rejected value [null]; codes    [projectmanagement.Project.name.nullable.error.projectmanagement.Project.name,projectmanagement.Project.name.nullable.error.name,projectmanagement.Project.name.nullable.error.java.lang.String,projectmanagement.Project.name.nullable.error,project.name.nullable.error.projectmanagement.Project.name,project.name.nullable.error.name,project.name.nullable.error.java.lang.String,project.name.nullable.error,projectmanagement.Project.name.nullable.projectmanagement.Project.name,projectmanagement.Project.name.nullable.name,projectmanagement.Project.name.nullable.java.lang.String,projectmanagement.Project.name.nullable,project.name.nullable.projectmanagement.Project.name,project.name.nullable.name,project.name.nullable.java.lang.String,project.name.nullable,nullable.projectmanagement.Project.name,nullable.name,nullable.java.lang.String,nullable]; arguments [name,class projectmanagement.Project]; default message [Property [{0}] of class [{1}] cannot be null]

sql日志显示:

Hibernate: select this_.id as id0_0_, this_.version as version0_0_, this_.name as name0_0_ from project this_ limit ?
Hibernate: select count(*) as y0_ from project this_

params.dump()显示:

<org.codehaus.groovy.grails.web.servlet.mvc.GrailsParameterMap@6715e66f request=org.apache.catalina.core.ApplicationHttpRequest@2a6e8f nestedDateMap=[:] wrappedMap=[name:kkjkj, create:Create, action:save, controller:project]>

我正在使用Grails 2.2和Intellij Idea IDE。虽然我在过去的5-6个月里没有使用过Grails,但我记不起以前遇到过同样的问题了。

1 个答案:

答案 0 :(得分:2)

我不确定这是否会导致问题,但在您的域类Name中以大写N开头,而参数地图包含name小写n