JFinal オンラインマニュアル
/ Interceptor
Interceptor
Interceptor 可以對(duì)方法進(jìn)行攔截,并提供機(jī)會(huì)在方法的前后添加切面代碼,實(shí)現(xiàn) AOP 的 核心目標(biāo)。Interceptor 接口僅僅定了一個(gè)方法 void intercept(Invocation inv)。以下是簡(jiǎn)單的示例:
public class DemoInterceptor implements Interceptor { public void intercept(Invocation inv) { System.out.println("Before method invoking"); inv.invoke(); System.out.println("After method invoking"); } }
以上代碼中的 DemoInterceptor 將攔截目標(biāo)方法,并且在目標(biāo)方法調(diào)用前后向控制臺(tái)輸出 文本。inv.invoke()這一行代碼是對(duì)目標(biāo)方法的調(diào)用,在這一行代碼的前后插入切面代碼可以很 方便地實(shí)現(xiàn) AOP。
nvocation 作為 Interceptor 接口 intercept 方法中的唯一參數(shù),提供了很多便利的方法在攔 截器中使用。以下為 Invocation 中的方法:
