gongchunyi
17 小时以前 c698a63d38add7fe43440099f59049b290006602
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
 
/**
 * <br>
 * 统计类型默认值注解切面
 * </br>
 *
 * @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);
    }
}