Java tutorial
/** * Copyright (c) 2011-2020, hubin (jobob@qq.com). * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.baomidou.framework.aop; import java.lang.reflect.Method; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import com.baomidou.framework.annotations.Log; /** * <p> * ?? * </p> * * @author hubin * @Date 2016-05-09 */ public class LogAspect { /** * */ private LogPoint logPoint; /** * ?? * * @param joinPoint * * @return * @throws Throwable * */ @Around(value = "@annotation(com.baomidou.framework.annotations.Log)") public Object saveLog(ProceedingJoinPoint joinPoint) throws Throwable { /** * ?Log */ String methodName = joinPoint.getSignature().getName(); Method method = currentMethod(joinPoint, methodName); Log log = method.getAnnotation(Log.class); /** * */ if (log != null) { logPoint.saveLog(joinPoint, methodName, log.value()); } /** * */ return joinPoint.proceed(); } /** * ?? * * @param joinPoint * * @param methodName * ?? * @return */ private Method currentMethod(ProceedingJoinPoint joinPoint, String methodName) { /** * ??? */ Method[] methods = joinPoint.getTarget().getClass().getMethods(); Method resultMethod = null; for (Method method : methods) { if (method.getName().equals(methodName)) { resultMethod = method; break; } } return resultMethod; } public LogPoint getLogPoint() { return logPoint; } public void setLogPoint(LogPoint logPoint) { this.logPoint = logPoint; } }