我创建了一个只包含方法的Controller
命名。另一个将包含所有方法并使用using注释。InterceptionLogger.java
Interception
Controller
Application
action
Interception
@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
没有在控制台中打印?
如何让它发挥作用?