java學習

          java學習

           

          jfinal攔截器筆記5

          Interceptors是jfinal  aop的實現方式,通過實現Interceptor接口以及使用@Before可以
          精確進行配置,
          Interceptor接口僅僅定了一個方法void intercept(ActionInvocation ai);
          我們可以讓一個類實現這個接口,重寫方法,如:
          public class DemoInterceptor implements Interceptor {
          public void intercept(ActionInvocation ai) {
          System.out.println("Before action invoking");
          ai.invoke();
          System.out.println("After action invoking");
          }
          }
          就寫好了一個攔截器。
          攔截器配置有三個級別,global級,controller級,action級。global級的攔截器將對所有的
          action進行攔截,controller級攔截器將對該controller中的所以action攔截,action級攔截器
          只對該action進行攔截。
          global級攔截器在
          public void configInterceptor(Interceptors me) {
                  me.add(new DemoInterceptor());           
          }
          中配置,controller級攔截器使用@Before放在controller類定以前進行配置,action級攔截器
          使用@Before放在action定義前進行配置。具體配置如下:
          @Before(DemoInterceptor.class) // 配置一個Controller級別的攔截器
          public class HelloController extends Controller {
          @Before(AaaInterceptor.class)
          public void index() {
          renderText("配置一個action級別的攔截器");
          }
          @Before({AaaInterceptor.class, BbbInterceptor.class})
          public void test() {
          renderText("配置多個action級別的攔截器");
          }
          @ClearInterceptor
          public void login() {
          renderText("清除上一級別(Controller級)的攔截器");
          }
          @ClearInterceptor(ClearLayer.ALL)
          public void clearAllLayers() {
          renderText("清除所有級別(Global級與Controller級)的攔截器");
          }
          }

          posted on 2013-01-10 14:05 楊軍威 閱讀(8695) 評論(1)  編輯  收藏

          評論

          # re: jfinal攔截器筆記5[未登錄] 2015-07-02 11:13 123

          2132  回復  更多評論   


          只有注冊用戶登錄后才能發(fā)表評論。


          網站導航:
           

          導航

          統(tǒng)計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 讷河市| 青阳县| 姜堰市| 江陵县| 蕲春县| 武胜县| 莎车县| 永嘉县| 水富县| 忻州市| 大兴区| 绥化市| 岱山县| 开化县| 视频| 青川县| 夏津县| 连江县| 凌源市| 通道| 万宁市| 泉州市| 玛纳斯县| 措勤县| 繁昌县| 温宿县| 上犹县| 云浮市| 乌鲁木齐县| 肇源县| 湾仔区| 新巴尔虎左旗| 循化| 高唐县| 聂拉木县| 新闻| 苏州市| 东阳市| 丰县| 科技| 潼关县|