1818
1919package org .hswebframework .web .aop ;
2020
21+ import com .google .common .collect .Maps ;
2122import lombok .AllArgsConstructor ;
2223import lombok .Getter ;
24+ import lombok .Setter ;
2325import org .aopalliance .intercept .MethodInvocation ;
2426import org .hswebframework .web .utils .AnnotationUtils ;
27+ import org .hswebframework .web .utils .DigestUtils ;
2528import org .reactivestreams .Publisher ;
2629import org .springframework .core .LocalVariableTableParameterNameDiscoverer ;
2730import org .springframework .core .ParameterNameDiscoverer ;
28- import org .springframework .util .DigestUtils ;
2931import reactor .core .publisher .Flux ;
3032import reactor .core .publisher .Mono ;
3133
@@ -48,25 +50,28 @@ public class MethodInterceptorHolder {
4850 public static final ParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer ();
4951
5052 public static MethodInterceptorHolder create (MethodInvocation invocation ) {
51- String id = DigestUtils .md5DigestAsHex (String .valueOf (invocation .getMethod ().hashCode ()).getBytes ());
5253 String [] argNames = nameDiscoverer .getParameterNames (invocation .getMethod ());
5354 Object [] args = invocation .getArguments ();
54- Map <String , Object > argMap = new LinkedHashMap <>();
55- String [] names = new String [args .length ];
56- for (int i = 0 , len = args .length ; i < len ; i ++) {
57- names [i ] = (argNames == null || argNames .length <= i || argNames [i ] == null ) ? "arg" + i : argNames [i ];
58- argMap .put (names [i ], args [i ]);
59- }
6055
61- return new MethodInterceptorHolder (id ,
62- invocation .getMethod (),
63- invocation .getThis (),
64- args ,
65- names ,
66- argMap );
56+ String [] names ;
57+ //参数名与参数长度不一致,则填充argx来作为参数名
58+ if (argNames == null || argNames .length != args .length ) {
59+ names = new String [args .length ];
60+ for (int i = 0 , len = args .length ; i < len ; i ++) {
61+ names [i ] = (argNames == null || argNames .length <= i || argNames [i ] == null ) ? "arg" + i : argNames [i ];
62+ }
63+ } else {
64+ names = argNames ;
65+ }
66+ return new MethodInterceptorHolder (null ,
67+ invocation .getMethod (),
68+ invocation .getThis (),
69+ args ,
70+ names ,
71+ null );
6772 }
6873
69- private final String id ;
74+ private String id ;
7075
7176 private final Method method ;
7277
@@ -76,8 +81,27 @@ public static MethodInterceptorHolder create(MethodInvocation invocation) {
7681
7782 private final String [] argumentsNames ;
7883
79- private final Map <String , Object > namedArguments ;
84+ private Map <String , Object > namedArguments ;
85+
86+ public String getId () {
87+ if (id == null ) {
88+ id = DigestUtils .md5Hex (method .toString ());
89+ }
90+ return id ;
91+ }
8092
93+ protected Map <String , Object > createNamedArguments () {
94+ Map <String , Object > namedArguments = Maps .newLinkedHashMapWithExpectedSize (arguments .length );
95+ for (int i = 0 , len = arguments .length ; i < len ; i ++) {
96+ namedArguments .put (argumentsNames [i ], arguments [i ]);
97+ }
98+ return namedArguments ;
99+
100+ }
101+
102+ public Map <String , Object > getNamedArguments () {
103+ return namedArguments == null ? namedArguments = createNamedArguments () : namedArguments ;
104+ }
81105
82106 public <T extends Annotation > T findMethodAnnotation (Class <T > annClass ) {
83107 return AnnotationUtils .findMethodAnnotation (annClass , method , annClass );
0 commit comments