0

我创建了一个只包含方法的Controller命名。另一个将包含所有方法并使用using注释。InterceptionLogger.javaInterceptionControllerApplicationactionInterception@With

这是Application.java控制器:

@With(InterceptionLogger.class)
public class Application extends Controller {

public static void index() {
    System.out.println("Inside index!!!");
    render();
}

public static void welcome(String txtName){     
    render(txtName);
}

如果InterceptionLogger.java控制器是这样的:

public class InterceptionLogger extends Controller {   

@Before
static void logBefore(){
    System.out.println("Inside \"logBefore\" method of App Controller");
}

@After
static void logAfter(){
    System.out.println("Inside \"logAfter\" method of App Controller");
}

}

当我运行应用程序时,输出是:

Inside "logBefore" method of App Controller
Inside index!!!
Inside "logAfter" method of App Controller

很好,正如预期的那样。

但是,如果我将其更改InterceptionLogger.java为:

public class InterceptionLogger extends Controller {   

@Before(only="welcome")
static void logBefore(){
    System.out.println("Inside \"logBefore\" method of App Controller");
}

@After(only="index")
static void logAfter(){
    System.out.println("Inside \"logAfter\" method of App Controller");
}

}

然后我得到这个输出index

Inside index!!!

在这种情况下,为什么该语句Inside "logAfter" method of App Controller没有在控制台中打印?

如何让它发挥作用?

4

1 回答 1

2

玩!正在寻找当前控制器中被拦截的方法。如果方法在另一个控制器中,您需要提供完整路径:

@Before(only="Application.welcome")
static void logBefore(){
    System.out.println("Inside \"logBefore\" method of App Controller");
}

@After(only="Application.index")
static void logAfter(){
    System.out.println("Inside \"logAfter\" method of App Controller");
}
于 2013-02-03T10:35:57.800 回答