AOP日志-前置通知操作
生活随笔
收集整理的這篇文章主要介紹了
AOP日志-前置通知操作
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
@Component
@Aspect
public class LogAop {@Autowiredprivate HttpServletRequest request;@Autowiredprivate ISysLogService sysLogService;private Date startTime; // 訪問(wèn)時(shí)間private Class executionClass;// 訪問(wèn)的類 private Method executionMethod; // 訪問(wèn)的方法// 主要獲取訪問(wèn)時(shí)間、訪問(wèn)的類、訪問(wèn)的方法@Before("execution(* com.learn.ssm.controller.*.*(..))")public void doBefore(JoinPoint jp) throws NoSuchMethodException, SecurityException {startTime = new Date(); // 訪問(wèn)時(shí)間// 獲取訪問(wèn)的類executionClass = jp.getTarget().getClass();// 獲取訪問(wèn)的方法String methodName = jp.getSignature().getName();// 獲取訪問(wèn)的方法的名稱Object[] args = jp.getArgs();// 獲取訪問(wèn)的方法的參數(shù)if (args == null || args.length == 0) {// 無(wú)參數(shù)executionMethod = executionClass.getMethod(methodName); // 只能獲取無(wú)參數(shù)方法} else {// 有參數(shù),就將args中所有元素遍歷,獲取對(duì)應(yīng)的Class,裝入到一個(gè)Class[]Class[] classArgs = new Class[args.length];for (int i = 0; i < args.length; i++) {classArgs[i] = args[i].getClass();}executionMethod = executionClass.getMethod(methodName, classArgs);// 獲取有參數(shù)方法}} }
?
總結(jié)
以上是生活随笔為你收集整理的AOP日志-前置通知操作的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: AOP日志-域对象创建与基本操作介绍
- 下一篇: AOP日志-后置通知