如何通过不是域类实例的 Controller 将参数传递到groovy服务器页面?

最佳答案

您将参数放入返回到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

10-06 07:02