Grails:我如何更改默认视图位置? [英] Grails: How can I change default view location?

查看:131
本文介绍了Grails:我如何更改默认视图位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有控制器 AdminTagController 。默认情况下,视图将位于 / adminTag 文件夹中。是否可以将此控制器的默认文件夹更改为 / admin / view ?我可以为每个方法指定视图,但不是很酷



谢谢

解决方案

可以使用您的 afterInterceptor 对其进行更改控制器。检查示例:

  def afterInterceptor = {model,modelAndView  - > 
println当前视图是$ {modelAndView.viewName}
if(model.someVar){
modelAndView.viewName =/ mycontroller / someotherview
}
printlnView is now $ {modelAndView.viewName}
}

这适用于您控制器的所有操作。

I've got controller AdminTagController. By default view will be located in /adminTag folder. Is it possible to change default folder for this controller to /admin/view? I can specify view for each method but it's not cool

Thank you

解决方案

It's possible to change it with the afterInterceptor of your controller. Check the example:

def afterInterceptor = { model, modelAndView ->
    println "Current view is ${modelAndView.viewName}"
    if (model.someVar) {
        modelAndView.viewName = "/mycontroller/someotherview"
    }
    println "View is now ${modelAndView.viewName}"
}

This is applied to all actions of your controller.

这篇关于Grails:我如何更改默认视图位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆