先定义一个注解logPrint,然后在注解上加一个环绕
private static final Logger logger = Logger.getLogger(Test.class); @Around("@annotation(logPrint)") public Object around(ProceedingJoinPoint pjp) throws Throwable { String method = pjp.getSignature().toString(); Object result; try { result = pjp.proceed(); logger.info("调用方法-{} 参数-{} 返回值-{}",method,pjp.getArgs(), JSON.toJSONString(result)); } catch (Exception e) { logger.error("调用方法-{} 参数-{} 异常-{}",method,JSON.toJSONString(pjp.getArgs()),e); throw e; } return result; }