配置文件

<bean name="methodParamHandler" class="com.grem.v4.commons.MethodParamHandler"></bean>
    <aop:config>
        <aop:aspect id="myAspect" ref="methodParamHandler">
                <aop:pointcut id="allAddMethod" expression="execution(* com.grem.v4.biz.impl.OtherBizImpl.*(..))"/>
                <aop:before method="methodFilter" pointcut-ref="allAddMethod"/>
            <!-- 
                <aop:after method="methodFilter" pointcut-ref="allAddMethod"/>
                <aop:after-returning method="methodFilter" pointcut-ref="allAddMethod"/> -->
        </aop:aspect>
    </aop:config>

 

 

代码

 

package com.grem.v4.commons;

import java.lang.reflect.Method;

import org.aspectj.lang.JoinPoint;

public class MethodParamHandler {
    public void methodFilter(JoinPoint joinPoint) throws SecurityException, NoSuchMethodException{

        System.out.println("========Class:["+joinPoint.getSignature().getDeclaringTypeName()+"]==>method:["+joinPoint.getSignature().getName()+"]========");//这个是获得方法名
        if(joinPoint.getArgs()!=null){
            System.out.print("param:( ");
            for (Object obj : joinPoint.getArgs()) {
                System.out.print("\n["+obj);
                if(obj.getClass().getMethods().length>0){
                    System.out.print("\t  {");
                    for (Method method :obj.getClass().getMethods()) {
                        try {
                            
                            System.out.print(method.getName()+":"+method.invoke(obj)+",");
                        } catch (Exception e) {
                        }
                    }
                    System.out.print("}  ");
                }
                System.out.print("],");
            }
            System.out.print(") ");
        }
        System.out.println("");
    }
}
posted on 2014-04-25 15:48  gpb123q  阅读(173)  评论(0)    收藏  举报