将 grails 操作映射到父控制器
我想将子类中的一些操作映射到他们的超类,但我无法弄清楚。下面的例子......
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果发现它不起作用,因为参数略有不同。它似乎确实按预期工作。如果您遇到问题,请确保任何继承类的参数与父类完全相同。
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.