Spring AOP进行切面拦截@Aspect

4 篇文章 0 订阅
package com.xyz.axy.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.xyz.axy.domain.entity.WeuiEntity;

@Aspect
@Component
public class LogAspect {

	private final static Logger logger=LoggerFactory.getLogger(LogAspect.class);
	
	 @Pointcut("execution(* com.xyz.axy.service.*.*(..))")
	 public void pointcutName(){}
	 
//	 @Before("pointcutName()")
//	 public void before(JoinPoint joinPoint){
//	        logger.info("before");
//	        Object[] args =joinPoint.getArgs();
//	        for (Object object : args) {
//				 logger.info("before参数:"+object.toString());
//			}
//	 }
	 
	@Around("pointcutName()")
	public Object around(ProceedingJoinPoint joinPoint) {
		logger.info("========获取参数开始=========");
		Object[] args = joinPoint.getArgs();
		for (Object object : args) {

			if (object instanceof WeuiEntity) {
				WeuiEntity we = (WeuiEntity) object;
				logger.info(we.getMsg());
				logger.info(we.getTitle());
			} else {
				logger.info("around参数:" + object.toString());
			}
		}
		logger.info("========获取参数结束=========");
		Object result = null;
		logger.info("around1");
		try {
			result = joinPoint.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		}
		logger.info("around2");

		return result;
	}
	 
//	 @After("pointcutName()")
//	 public void after(JoinPoint joinPoint) {
//		 logger.info("after");
//		 Object[] args =joinPoint.getArgs();
//	        for (Object object : args) {
//				 logger.info("after参数:"+object.toString());
//			}
//	 }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值