RT 用AOP记录日志 哪个用户 什么时间 做了什么操作 

解决方案 »

  1.   

    用Spring的aop和log4j配合,前置通知就行了
      

  2.   


    <bean name="logManager" class="com.study.spring.aop.LogManager"></bean>

    <bean name="LogTestService" class="com.study.spring.aop.service.impl.LogTestServiceImpl"></bean>

    <aop:config>
    <aop:aspect ref="logManager">
    <aop:pointcut id="logAOP" expression="execution(* com.study.spring.aop.service.impl.LogTestServiceImpl.say(..))"/>
    <aop:after method="printLog" pointcut-ref="logAOP"/>
    </aop:aspect>
    </aop:config>
    package com.study.spring.aop;import org.aspectj.lang.JoinPoint;public class LogManager{ public void printLog(JoinPoint joinpoint) throws Exception{
    Object[] objs = joinpoint.getArgs();
    for(Object obj : objs){
    System.out.println(obj);
    }
    System.out.println("spring aop test.");
    }
    }//test
    package com.study.spring.aop;import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;import com.study.spring.aop.service.LogTestService;public class Test { public static void main(String[] args) throws Exception {
    ApplicationContext act = new ClassPathXmlApplicationContext("applicationContext.xml");
    LogTestService service = (LogTestService)act.getBean("LogTestService");
    try {
    service.say(1);
    } catch (RuntimeException e) {
    e.printStackTrace();
    }
    }
    }//service
    package com.study.spring.aop.service;public interface LogTestService { public int say(int i);
    }
    //impl
    package com.study.spring.aop.service.impl;import com.study.spring.aop.service.LogTestService;public class LogTestServiceImpl implements LogTestService{ public int say(int i){
    System.out.println("hello world!");
    return 1;
    }
    }
      

  3.   

    用spring aop吧 很简单的 基于注解的