【问题标题】:How can i respond to the same gsp view from the controller?我如何从控制器响应相同的 gsp 视图?
【发布时间】:2016-11-03 08:13:00
【问题描述】:

我对 grails 很陌生,想知道如何将响应对象用于同一视图。 注意:我的问题可能不清楚 - 但请检查以下内容。

  1. 我有一个名为“ProcessController.groovy”的控制器,其中有 2 个方法。
  2. 我只有一个名为“create.gsp”的 gsp

    class PublishedSetController { 
        ...
    
        def create() {
            Person p = new Person()
            ...
    
            respond p // Working fine and this forward's to the view "create.gsp"
        }
    
        def createClone() {
            Person p = new Person()
            p.name = 'joe'
            ...
    
            // Would like to forward to view "create.gsp"
            respond view: 'create', model: p
        }
    }
    
    Error:
        Could not resolve view with name 'createClone' in servlet with name 'grailsDispatcherServlet'
    

我知道 grails 主要是 codeByConvention - 但不确定如何解决此问题。 有谁能帮忙,谢谢。

【问题讨论】:

    标签: grails controller


    【解决方案1】:

    respond 的正确语法是:

    respond p, view: 'create'
    

    您可以在documentation 中阅读有关respond 的更多信息。

    【讨论】:

    • 谢谢@Joshua Moore,我正要添加文档:)
    • 不用担心,我已经在我修改后的答案中输入了它,但你在我完成之前就发布了。 ;)
    • 效果很好..我之前误解了文档 - 但现在它有意义了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-19
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 2018-09-01
    • 2012-12-14
    • 1970-01-01
    相关资源
    最近更新 更多