sage()); ? ? ? ? ? ? ? } ? ? ? ? ? } ? ? ? } ? ? ? ? /** ? ? * 后置通知 用于拦截Controller层记录用户的操作 ? ? * ? ? * @param joinPoint 切点 ? ? */? ? ? @After("controllerAspect()")? ? ? public? void after(JoinPoint joinPoint) {? ? ? ? ? /* HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();? ? ? ? ? HttpSession session = request.getSession();? */ ? ? ? ? //读取session中的用户? ? ? ? // User user = (User) session.getAttribute("user");? ? ? ? ? //请求的IP? ? ? ? ? //String ip = request.getRemoteAddr(); ? ? ? ? User user = new User(); ? ? ? ? user.setId(1); ? ? ? ? user.setName("张三"); ? ? ? ? String ip = "127.0.0.1"; ? ? ? ? try {? ? ? ? ? ? ? ? ? ? ? ? ? String targetName = joinPoint.getTarget().getClass().getName();? ? ? ? ? ? ? String methodName = joinPoint.getSignature().getName();? ? ? ? ? ? ? Object[] arguments = joinPoint.getArgs();? ? ? ? ? ? ? Class targetClass = Class.forName(targetName);? ? ? ? ? ? ? Method[] methods = targetClass.getMethods(); ? ? ? ? ? ? String operationType = ""; ? ? ? ? ? ? String operationName = ""; ? ? ? ? ? ? for (Method method : methods) {? ? ? ? ? ? ? ? ? if (method.getName().equals(methodName)) {? ? ? ? ? ? ? ? ? ? ? Class[] clazzs = method.getParameterTypes();? ? ? ? ? ? ? ? ? ? ? if (clazzs.length == arguments.length) {? ? ? ? ? ? ? ? ? ? ? ? ? operationType = method.getAnnotation(Log.class).operationType(); ? ? ? ? ? ? ? ? ? ? ? ? operationName = method.getAnnotation(Log.class).operationName(); ? ? ? ? ? ? ? ? ? ? ? ? break;? ? ? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? } ? ? ? ? ? ? //*========控制台输出=========*//? ? ? ? ? ? ? System.out.println("=====controller后置通知开始=====");? ? ? ? ? ? ? System.out.println("请求方法:" + (joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()")+"."+operationType);? ? ? ? ? ? ? System.out.println("方法描述:" + operationName);? ? ? ? ? ? ? System.out.println("请求人:" + user.getName());? ? ? ? ? ? ? System.out.println("请求IP:" + ip);? ? ? ? ? ? ? //*========数据库日志=========*//? ? ? ? ? ? ? SystemLog log = new SystemLog();? ? ? ? ? ? ? log.setId(UUID.randomUUID().toString()); ? ? ? ? ? ? log.setDescription(operationName);? ? ? ? ? ? ? log.setMethod((joinPoint.getTarget().getClass().getName() + "." + joinPoint.getSignature().getName() + "()")+"."+operationType);? ? ? ? ? ? ? log.setLogType((long)0);? ? ? ? ? ? ? log.setRequestIp(ip);? ? ? ? ? ? ? log.setExceptioncode( null);? ? ? ? ? ? ? log.setExceptionDetail( null);? ? ? ? ? ? ? log.setParams( null);? ? ? ? ? ? ? log.setCreateBy(user.getName());? ? ? ? ? ? ? log.setCreateDate(new Date());? ? ? ? ? ? ? //保存数据库? ? ? ? ? ? ? systemLogService.insert(log);? ? ? ? ? ? ? System.out.println("=====controller后置通知结束=====");? ? ? ? ? }? catch (Exception e) {? ? ? ? ? ? ? //记录本地异常日志? ? ? ? ? ? ? logger.error("==后置通知异常==");? ? ? ? ? ? ? logger.error("异常信息:{}", e.getMessage());? ? ? ? ? }? ? ? } ? ? ? ? //配置后置返回通知,使用在方法aspect()上注册的切入点 ? ? ? @AfterReturning("controllerAspect()") ? ? ? public void afterReturn(JoinPoint joinPoint){ ? ? ? ? ? System.out.println("=====执行controller后置返回通知=====");? ? ? ? ? ? ? ? if(logger.isInfoEnabled()){ ? ? ? ? ? ? ? ? ? logger.info("afterReturn " + joinPoint); ? ? ? ? ? ? ? } ? ? ? } ? ? ? ? /** ? ? * 异常通知 用于拦截记录异常日志 ? ? * ? ? * @param joinPoint ? ? * @param e ? ? */? ? ? @AfterThrowing(pointcut = "controllerAspect()", throwing="e")? ? ? public? void doAfterThrowing(JoinPoint joinPoint, Throwable e) {? ? ? ? ? /*HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();? ? ? ? ? HttpSession session = request.getSession();? ? ? ? ? //读取s |