这是我的简单域类:
package projectmanagement
class Project {
String Name
static constraints = {
}
}
控制器上的保存方法(使用脚手架生成):
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,但我不记得以前遇到过同样的问题。