2011-01-07 127 views
12

如何通过不属于域类的实例的控制器将参数传递到常规服务器页面?从控制器传递的gsp参数

+0

可能与http://stackoverflow.com/q/2063220/6509 – 2011-01-07 09:53:04

回答

0

您返回与gsp具有相同名称的控制器的闭包中的参数。

6

你可以这样说:

在控制器:

def myaction = { 
    String name = "Tony Danza" 
    [name: name] 
} 

在GSP页面,您可以查看名称,像这样:

<body> 
    My name is ${name} 
</body> 
21

你把你的参数代入模型对象映射返回到您的GSP,例如:

def index = { def hobbies = ["basketball", "photography"] 
render(view: "index", model: [name: "Maricel", hobbies: hobbies]) } 

然后你得到那些你在你的模型图使用的名称访问它们的值,例如:

My name is ${name} and my hobbies are: 
<ul> 
<g:each in="${hobbies}" var="hobby"> 
<li>${hobby}</li> 
</g:each> 
</ul> 

这应该显示如下:

My name is Maricel and my hobbies are: 

- basketball 
- photography