codecamp

用json文件声明Aop切片

需使用的类

  • org.nutz.ioc.aop.config.impl.JsonAopConfigration

看看一个示例的ioc配置文件

配置示例:

var ioc = {
    log : {
        type :'org.nutz.aop.interceptor.LoggingMethodInterceptor'
    },
    myMI : {
        type : 'org.nutz.ioc.aop.config.impl.MyMI'
    },
    pet2 : {
    type : "org.nutz.ioc.aop.config.impl.Pet2"
    },
    
    $aop : {
        type : 'org.nutz.ioc.aop.config.impl.JsonAopConfigration',
        fields : {
            itemList : [
                ['.+','toString','ioc:log'],
                ['.+','.+','ioc:myMI'],
                ['.+','.+','org.nutz.ioc.aop.config.impl.MyMI2','false']
            ]
        }
    }
}

可以看到, 除了$aop这个beanName外,其他的与普通的ioc配置文件没有任何区别.

$aop ,其实是org.nutz.ioc.aop.config.AopConfigration接口的IOCNAME字段的值, 只有你声明这个名字,且类型为这个接口的实现,就能轻易的配置Ioc.

估计你已经猜到,org.nutz.ioc.aop.config.impl.JsonAopConfigration就是其中一个实现!

细看这个部分代码:

        fields : {
            itemList : [
                ['.+','toString','ioc:log'],
                ['.+','.+','ioc:myMI'],
                ['.+','.+','org.nutz.ioc.aop.config.impl.MyMI2','false']
            ]
        }

使用JsonAopConfigration,只需要为其itemList赋值.

需要什么值? 对,一个数组.

数组的每一行,对应一条规则:

['.+','toString','ioc:log'],
['.+','.+','ioc:myMI']
['com\.wendal\.nutz\..+','get.+','org.nutz.ioc.aop.config.impl.MyMI2','false']

规则如下:

  • 第一个值,对应className,必选,用于匹配类的全称的正则表达式
  • 第二个值,对应methodName,必选,用于匹配方法名的正则表达式
  • 第三个值,对应interceptorName,必选,如果以ioc:开头,则代表对于ioc容器的一个对象,否则,将认为是一个类名
  • 第四个值,对应singleton,可选,仅当interceptorName为类名时有效
AOP -- 声明式切片
Nutz.Json 基本用法
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

表达式引擎

maplist结构

图像处理小军刀

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }