Grails Controller - redirect 方法

时间:2019-11-11
本文章向大家介绍Grails Controller - redirect 方法,主要包括Grails Controller - redirect 方法使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

官方文档:

网页跳转方法1:

// 在一个Action中直接跳转到另外一个Action中,另外的Action接受一个opportunity对象,这里直接通过id传过去就行,约定规则,就可以获取对应内容。
redirect controller: "opportunity", action: "show", id: opportunityContract.opportunity.id
 
1
// 在一个Action中直接跳转到另外一个Action中,另外的Action接受一个opportunity对象,这里直接通过id传过去就行,约定规则,就可以获取对应内容。
2
redirect controller: "opportunity", action: "show", id: opportunityContract.opportunity.id

网页跳转方法2:

// Opportunity的show.gsp页面
http://localhost:8080/opportunity/show/56829

// RightCentification的Create Action:
def create()
{
    params['targetUri'] = request.getHeader("referer") // 存放到params里面
    respond new RightCertification(params)
}

// RightCentification的Create 页面,放到表单里面,再传递给后面Save Action:
http://localhost:8080/rightCertification/create?opportunity=56829
<g:hiddenField name="targetUri" value="${params?.targetUri}"></g:hiddenField>

//  RightCentification的 Save Action就可以直接跳转回Opportunity的show.gsp页面
redirect url: params['targetUri']
x
 
1
// Opportunity的show.gsp页面
2
http://localhost:8080/opportunity/show/56829
3
4
// RightCentification的Create Action:
5
def create()
6
{
7
    params['targetUri'] = request.getHeader("referer") // 存放到params里面
8
    respond new RightCertification(params)
9
}
10
11
// RightCentification的Create 页面,放到表单里面,再传递给后面Save Action:
12
http://localhost:8080/rightCertification/create?opportunity=56829
13
<g:hiddenField name="targetUri" value="${params?.targetUri}"></g:hiddenField>
14
15
//  RightCentification的 Save Action就可以直接跳转回Opportunity的show.gsp页面
16
redirect url: params['targetUri']
17

原文地址:https://www.cnblogs.com/duchaoqun/p/11834097.html