package com.ruoyi.home.aspectj; import com.ruoyi.home.annotation.DefaultType; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; import java.lang.reflect.Parameter; /** *
* 统计类型默认值注解切面 *
* * @author deslrey * @version 1.0 * @since 2026/2/5 */ @Aspect @Component public class DefaultTypeAspect { @Around("execution(* com.ruoyi.home.controller.*.*(.., @com.ruoyi.home.annotation.DefaultType (*), ..))") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { Object[] args = joinPoint.getArgs(); MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Parameter[] parameters = signature.getMethod().getParameters(); for (int i = 0; i < parameters.length; i++) { DefaultType annotation = parameters[i].getAnnotation(DefaultType.class); if (annotation != null && args[i] == null) { args[i] = Integer.parseInt(annotation.value()); } } return joinPoint.proceed(args); } }