我在 Windows 7 64 位上使用 Grails 2.5.1,在使用 Grails 命令生成控制器和视图之后
generate-all "*"
当我在控制器中添加任何新行时,出现以下错误:
编译错误:启动失败:E:\Development\eclipse\TekDays\grails- app\controllers\com\tekdays\TekEventController.groovy:47:不明确的表达式可能是一个无参数的闭包表达式,一个孤立的开放代码块,或者它可能会继续前一条语句;解决方案:添加一个显式参数列表,例如 {it -> ...},或者通过给它一个标签来强制它被视为一个开放块,例如 L:{...},或者删除前一个换行符,或添加显式分号 ';' @ 第 47 行,第 4 列。{ ^ 1 错误
这是我的控制器:
package com.tekdays
import static org.springframework.http.HttpStatus.*
@Transactional(readOnly = true)
class TekEventController
{
def taskService // this what i added
static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]
def index(Integer max)
{
params.max = Math.min(max ?: 10, 100)
respond TekEvent.list(params), model:[tekEventInstanceCount: TekEvent.count()]
}
def show(TekEvent tekEventInstance)
{
respond tekEventInstance
}
def create()
{
respond new TekEvent(params)
}
@Transactional
def save(TekEvent tekEventInstance)
{
if (tekEventInstance == null)
{
notFound()
return
}
if (tekEventInstance.hasErrors())
{
respond tekEventInstance.errors, view:'create'
return
}
tekEventInstance.save flush:true
taskService.addDefaultTasks(tekEventInstance) // this what i added
request.withFormat
{
form multipartForm
{
flash.message = message(code: 'default.created.message', args: [message(code: 'tekEvent.label', default: 'TekEvent'), tekEventInstance.id])
redirect tekEventInstance
}
'*' { respond tekEventInstance, [status: CREATED] }
}
}
def edit(TekEvent tekEventInstance)
{
respond tekEventInstance
}
@Transactional
def update(TekEvent tekEventInstance)
{
if (tekEventInstance == null)
{
notFound()
return
}
if (tekEventInstance.hasErrors())
{
respond tekEventInstance.errors, view:'edit'
return
}
tekEventInstance.save flush:true
request.withFormat
{
form multipartForm
{
flash.message = message(code: 'default.updated.message', args: [message(code: 'TekEvent.label', default: 'TekEvent'), tekEventInstance.id])
redirect tekEventInstance
}
'*'
{
respond tekEventInstance, [status: OK]
}
}
}
@Transactional
def delete(TekEvent tekEventInstance)
{
if (tekEventInstance == null)
{
notFound()
return
}
tekEventInstance.delete flush:true
request.withFormat
{
form multipartForm
{
flash.message = message(code: 'default.deleted.message', args: [message(code: 'TekEvent.label', default: 'TekEvent'), tekEventInstance.id])
redirect action:"index", method:"GET"
}
'*'
{
render status: NO_CONTENT
}
}
}
protected void notFound()
{
request.withFormat
{
form multipartForm
{
flash.message = message(code: 'default.not.found.message', args: [message(code: 'tekEvent.label', default: 'TekEvent'), params.id])
redirect action: "index", method: "GET"
}
'*'
{
render status: NOT_FOUND
}
}
}
}
有什么建议可以解决这个错误吗?谢谢