-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAOP文件
49 lines (42 loc) · 2.05 KB
/
AOP文件
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
41
42
43
44
45
46
47
48
49
拦截配置地址 https://blog.csdn.net/simba_1986/article/details/78300175
@Aspect
@Component
public class PropertyAspect {
private static final String point ="@annotation(com.zhuguang.zhou.annotation.PropertyFiltration)";
@Pointcut(point)
public void pointCut (){};
@Before("pointCut()" )
public void beforeInfo (JoinPoint joinPoint) {
System.out.println("切面执行在这.............." );
}
@AfterReturning(pointcut = "pointCut()" ,returning = "returnValue")
public void afterInfo (JoinPoint joinPoint,Object returnValue) {
try {
System.out.println("===========执行前的数据===============" + returnValue);
MethodSignature signature = (MethodSignature)joinPoint.getSignature();
Method method = signature.getMethod();
PropertyFiltration annotation = method.getAnnotation(PropertyFiltration.class);
String[] exclude = annotation.exclude();
Class<?> clazz = returnValue.getClass();
for (String name : exclude) {
Field field = clazz.getDeclaredField(name);
if (field != null) {
field.setAccessible(true);
field.set(returnValue,null);
JsonIgnore annotation1 = field.getAnnotation(JsonIgnore.class);
System.out.println("修改前的字段属性" + annotation1.value());
InvocationHandler h = Proxy.getInvocationHandler(annotation1);
Field hField = h.getClass().getDeclaredField("memberValues");
hField.setAccessible(true);
Map memberValues = (Map) hField.get(h);
// 修改 value 属性值
memberValues.put("value", false);
System.out.println("修改后的结构:" + annotation1.value());
}
}
System.out.println("..........执行后面的数据........." + returnValue);
} catch (Exception e) {
e.printStackTrace();
}
}
}