Summary
Demo
- 在一个Action中直接跳转到另外一个Action中,另外的Action接受一个opportunity对象,这里直接通过id传过去就行,约定规则,就可以获取对应内容。
redirect controller: "opportunity", action: "show", id: opportunityContract.opportunity.id
Demo
def create()
{
params['targetUri'] = request.getHeader("referer")
respond new RightCertification(params)
}
- 然后 RightCentification 的 Create 页面,放到表单里面,再传递给后面Save Action:
<g:hiddenField name="targetUri" value="${params?.targetUri}"></g:hiddenField>
- 最后 RightCentification 的 Save Action 就可以直接跳转回Opportunity的show.gsp页面
redirect url: params['targetUri']
Demo
- 在使用 redirect 方法返回错误信息。
- 如果让 URL 产生变化,且有问题的对象信息也返回去,就得用 message。
if (workflowTypeTeam.hasErrors())
{
transactionStatus.setRollbackOnly()
def error = workflowTypeTeam.errors.allErrors.first()
flash['message'] = message(code: error.defaultMessage.toString(), args: error.arguments)
redirect(action:'create')
return
}
Demo
- 直接跳转到另外一个Action,params 中会拼到目标的URL上,类似浏览器使用 GET 方式访问了目标 Action。
redirect(action: 'create', params: [workflowTypeTeam: workflowTypeTeam])