将 grails 操作映射到父控制器

发布于 2024-12-07 19:15:55 字数 623 浏览 1 评论 0原文

我想将子类中的一些操作映射到他们的超类,但我无法弄清楚。下面的例子......

abstract class A {
    abstract def foo()

    def aAction1 = {
       // do something
       render(view: '/someView')
    }
    def aAction2 = { 
       SomeObject someObject ->
       // do something
       render(view: '/someView2')
    }
}

class B extents A {
    def foo() { return "Hello World" }

    # map to parent action    
    # works fine
    def jump = super.&aAction1
    # doesnt work ... Why? and can I make it work?
    def swim = { SomeObject someObject ->
       super.aAction2(someObject)
    }
}

对此有什么想法吗?谢谢。

I would like to map some actions in a child class to their super class, but I cannot figure it out. Example below...

abstract class A {
    abstract def foo()

    def aAction1 = {
       // do something
       render(view: '/someView')
    }
    def aAction2 = { 
       SomeObject someObject ->
       // do something
       render(view: '/someView2')
    }
}

class B extents A {
    def foo() { return "Hello World" }

    # map to parent action    
    # works fine
    def jump = super.&aAction1
    # doesnt work ... Why? and can I make it work?
    def swim = { SomeObject someObject ->
       super.aAction2(someObject)
    }
}

Any ideas on this one? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红尘作伴 2024-12-14 19:15:55

结果发现它不起作用,因为参数略有不同。它似乎确实按预期工作。如果您遇到问题,请确保任何继承类的参数与父类完全相同。

So it turns out it didnt work because the parameters were slightly different. It does seem to work as expected. If you are having issues with this, make sure that the parameters for any inherited classes are exactly the same as the parent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文