0

我正在我的 ProjectController 中创建一个项目,它应该在创建后保存。但相反,它给了我以下例外:

 Class java.lang.ClassCastException 
Message  com.everyonecounts.padre.ProjectController$_closure1 cannot be cast to javax.servlet.ServletRequest

这是我的保存方法的代码:

def save() {
    log.debug(params)
    def projectInstance = new Project(params)
    if (!projectInstance.save(flush: false)) {
        log.debug("save failed")
        render(view: "create", model: [projectInstance: projectInstance])  
        return
    }


}

堆栈跟踪告诉我错误发生在渲染行。

4

1 回答 1

1

仔细查看后,我发现您实际上是在检查错误save而不是成功保存。您需要检查不成功的保存还是成功?

def save() {
    log.debug(params)
    def projectInstance = new Project(params)
    //If save was successful then the if block will not be executed.
    if (!projectInstance.save(flush: false)) {//Returns true on successful save.
        log.debug("save failed")
        render(view: "create", model: [projectInstance: projectInstance])  
        return
    }

    //There is nothing to render here in case the save was successful.
    //you would need something like below on save success
    //render(view: "create", model: [projectInstance: projectInstance])  

}
于 2013-05-28T23:50:54.527 回答