3
這是我的簡單域類:Grails的錯誤屬性[{0}]類的[{1}]不能爲空 - 對基本的grails應用
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()顯示:
<[email protected]15e66f [email protected] nestedDateMap=[:] wrappedMap=[name:kkjkj, create:Create, action:save, controller:project]>
我使用的Grails 2.2和IntelliJ IDEA的IDE。儘管過去5-6個月我沒有使用過Grails,但我不記得之前有同樣的問題。
確保'動態'數據綁定是適當的。 'params'有'name'? – dmahapatro 2013-04-25 18:21:08
在問題中添加了params.dump()。看起來params有名字。 – biztiger 2013-04-25 18:31:11
也大多數代碼是自動生成的。我只創建了domainclass。 – biztiger 2013-04-25 18:33:18