Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在传递参数时重定向到Grails中的控制器_Grails - Fatal编程技术网

如何在传递参数时重定向到Grails中的控制器

如何在传递参数时重定向到Grails中的控制器,grails,Grails,我的控制器中有2个动作 def listGame(){ def category = GameCategory.list() def currentCategory = params.categoryName def myCategory=GameCategory.findByCategoryName(currentCategory) def games = myCategory.games [currentCategory:currentCategory, ca

我的控制器中有2个动作

def listGame(){
   def category = GameCategory.list()
   def currentCategory = params.categoryName
   def myCategory=GameCategory.findByCategoryName(currentCategory)
   def games = myCategory.games

   [currentCategory:currentCategory, category:category, games:games]

}
def listGameByPlatform(){
   def platform = params.platform 
   redirect(view: "listGame")
}
我只在单击某个按钮时访问listGameByPlatform,这就是它被分隔的原因


我有listGame.gsp,但我没有listGameByPlatform.gsp,所以我想将我的listGameByPlatform操作重定向到listGame,但我也想将平台作为参数传递到listGame.gsp,可能吗?

当然可以,只需在其中添加
参数:[platform:platform]
请参阅

如果要保存步骤,也可以将所有参数传递到:
parameters:params
。 然后,要将其添加到gsp中,只需在操作中将其添加到地图中:

 [currentCategory:currentCategory, category:category, games:games, platform: params.platform]

我不需要更改我的listGame操作的任何内容,以便我的listGame.gsp可以访问平台?哦,我没有注意到这一部分,是的,我将更新我的答案。出现一个错误,说“无法在null对象上获取属性'games'”突出显示def games=myCategory.games这是我在视图中的代码,这是因为您没有所谓的平台。。。这里有params.platform对象,可以传递给gsp,但很可能它只是一个字符串。。。所以我不完全确定你想做什么。我现在的代码中有一个叫做平台的东西。我在我的listGame操作[currentCategory:currentCategory,category:category,games:games,platform:platform]中添加了def platform=platform.list()
 [currentCategory:currentCategory, category:category, games:games, platform: params.platform]