Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Inheritance 如何将拦截器链接在一起?_Inheritance_Grails_Interceptor - Fatal编程技术网

Inheritance 如何将拦截器链接在一起?

Inheritance 如何将拦截器链接在一起?,inheritance,grails,interceptor,Inheritance,Grails,Interceptor,我有一个控制器,它从一个类继承,该类具有一个beforeInterceptor 这是我的基础课 class FooBase { def beforeInterceptor = [action: {parentInterceptor()}] def parentInterceptor() { render("Snarge") } } 以下是无法工作的控制器版本 class BrokenController extends FooBase { de

我有一个控制器,它从一个类继承,该类具有一个
beforeInterceptor

这是我的基础课

class FooBase {
    def beforeInterceptor = [action: {parentInterceptor()}]

    def parentInterceptor() {
        render("Snarge")
    }
}
以下是无法工作的控制器版本

class BrokenController extends FooBase
{
    def beforeInterceptor = [action: {childInterceptor()}]

    def childInterceptor() {
        super.beforeInterceptor.action.call()
        render("Bar")
    }

    def index = {
        render("Foo")
    }
}
这是一个可行的版本

当我在
WorkingController
上调用index时,我得到了输出
SnargeBarFoo
。当我在
BrokenController
上调用index时,我得到一个
IllegalAccessError

我想我有一个可行的版本,所以我的问题更多的是关于这里发生了什么?为什么一个版本可以从子类访问父类,而另一个版本不能


我正在寻找的用例是能够将拦截器函数与
功能一起使用,但
功能除外。这就要求在使用map实现拦截器时能够链接拦截器

两者之间存在差异

this.

以下代码有效-检查第三行:

class BrokenController extends FooBase
{
    def beforeInterceptor = [action: {this&childInterceptor()}]

    def childInterceptor() {
        super.beforeInterceptor.action.call()
        render("Bar")
    }

    def index = {
        render("Foo")
    }
}
文件对此作了如下说明&

Method Reference     .&      Get a reference to a method, can be useful for creating closures from methods 

所以我不确定,但我想它与调用方法的范围有关。可能系统创建了某种类型的helper类来执行闭包,从而导致该类没有super.beforeInterceptor方法。

您找到解决此问题的方法了吗?
class BrokenController extends FooBase
{
    def beforeInterceptor = [action: {this&childInterceptor()}]

    def childInterceptor() {
        super.beforeInterceptor.action.call()
        render("Bar")
    }

    def index = {
        render("Foo")
    }
}
Method Reference     .&      Get a reference to a method, can be useful for creating closures from methods