如何在Grails2.3.0控制器中重定向和响应save操作 request.withFormat{ 形式{ 重定向humanInstance //解释:像重定向一样的旧grails重定向(操作:“show”,id:humanInstance.id) //但在2.3.0中,通过重定向humanInstance,我看到这条语句转到了def show(HumanHumanInstance)操作 //Q1:它如何理解必须重定向def show(Human humanInstance)操作? //因为这里有那么多的方法可以接受人文关怀 //问题2:在哪里处理? } '*' { 响应humanInstance[状态:已创建] } //解释:我在上面的{worksfornormalcall}'*'{worksforrestcall}中测试了它 //问题3:什么是“*”运算符?它的名称是什么? }

如何在Grails2.3.0控制器中重定向和响应save操作 request.withFormat{ 形式{ 重定向humanInstance //解释:像重定向一样的旧grails重定向(操作:“show”,id:humanInstance.id) //但在2.3.0中,通过重定向humanInstance,我看到这条语句转到了def show(HumanHumanInstance)操作 //Q1:它如何理解必须重定向def show(Human humanInstance)操作? //因为这里有那么多的方法可以接受人文关怀 //问题2:在哪里处理? } '*' { 响应humanInstance[状态:已创建] } //解释:我在上面的{worksfornormalcall}'*'{worksforrestcall}中测试了它 //问题3:什么是“*”运算符?它的名称是什么? },grails,controller,Grails,Controller,“*”是一种catch-all,它与一个代码块相关联,如果没有其他块与accept头匹配,则应该执行该代码块。请参阅以下内容 request.withFormat { form { redirect humanInstance //Explain : old grails redirect like redirect(action: "show", id: humanInstance.id)

“*”是一种catch-all,它与一个代码块相关联,如果没有其他块与accept头匹配,则应该执行该代码块。请参阅以下内容

request.withFormat { form { redirect humanInstance //Explain : old grails redirect like redirect(action: "show", id: humanInstance.id) //but in 2.3.0 by redirect humanInstance this statement i saw it goes to def show(Human humanInstance) action //Q1: how it understand that it has to redirect def show(Human humanInstance) action ? //cause here so many methods which receives humanInstance //Q2: And where it get processed ? } '*' { respond humanInstance, [status: CREATED] } //Explain : I tested it that in the above {works for normalCall}'*'{works for restCall} //Q3: What is '*' operator do here what it's name? } 围绕这一点,您可能需要了解很多内容,包括您配置的mime类型。您应该查看官方用户指南的内容协商部分

我希望这会有帮助

更新:

当您调用redirect(someDomainClassInstance)时,您将在

那叫

那叫

这就叫


此时,“method”的值是“GET_ID”。与GET_ID关联的值为“show”,这表示您将重定向到show方法。

谢谢Jeff,第3季度的回答很好,请回答Q1和Q2。答案太长,不适合此评论,因此我添加了另一个答案。我看过你的几个问题,它们很难回答,因为你把几个问题堆在一个帖子里,大部分都是不连贯的,连贯的部分被不连贯的部分复杂化了,这意味着给你有用的信息需要付出比实际更多的努力。如果你不把问题混为一谈,让它们更简单,你的问题会更容易回答。我删除了第二个答案,并将其内容粘贴到第一个答案中,第一个答案已经被接受。我认为这将使这个问题更容易看。我认为答案中“更新”之后的所有内容现在都涉及到Q1和Q2。你真的不应该这样把这些问题捆在一起。它不必要地使事情复杂化。
request.withFormat {
    xml {
        // execute this if the request content type is xml
    }
    json {
        // execute this if the request content type is json
    }
    '*' {
        // execute this if neither of the other 2 matched the request's content type
    }
}