切面拦截指定注解.
/**
* 切面拦截
*/
@Aspect
@Component
@Slf4j
public class ReportAspect {
/**
* 定义切点Pointcut
*/
@Pointcut("@annotation(指定注解)")
public void excudeService() {
}
@Before("excudeService()")
public void doBefore(JoinPoint point) throws Throwable {
handleDataScope(point);
}
protected void handleDataScope(final JoinPoint joinPoint) {
StringBuilder sqlString = new StringBuilder();
//判断是否有注解
GetListIO annotationLog = getAnnotationLog(joinPoint);
if (null == annotationLog) {
return;
}
BaseEntity baseEntity = null;
Object[] objs = joinPoint.getArgs();
if (null == objs || 0 == objs.length) {
return;
}
//遍历方法的参数,获取第一个为实体类的参数
for (Object arg : joinPoint.getArgs()) {
if (null != arg && arg instanceof BaseEntity) {
baseEntity = (BaseEntity) arg;
break;
}
}
if (null == baseEntity) {
return;
}
}
/**
* 是否存在注解,如果存在就获取
*/
private GetListIO getAnnotationLog(JoinPoint joinPoint) {
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method method = methodSignature.getMethod();
if (method != null && method.isAnnotationPresent(GetListIO.class)) {
return method.getAnnotation(GetListIO.class);
}
return null;
}
}