1.測試類參數
public JsonResult<String> test(@SocketParam("a") String a) {//自定義注解的參數和方法的參數名字相同
JsonResult<String> reSocket = new JsonResult<>();
reSocket.setResult("dddd");
reSocket.setStatus(JsonResult.SUCCESS);
System.out.println(a);
return reSocket;
}
2.獲取參數名字
Method[] methods = cla.getMethods();//獲取類下的所有方法 cla是該方法的類
for(Method method:methods){
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations != null && parameterAnnotations.length > 0) {
String[] parameterNames = new String[parameterAnnotations.length];
int m = 0;
for (Annotation[] parameterAnnotation : parameterAnnotations) {
for (Annotation annotation : parameterAnnotation) {
if (annotation instanceof SocketParam) {
SocketParam param = (SocketParam) annotation;
parameterNames[m++] = param.value();
}
}
}
system.out.println(Arrays.toString(parameterNames));
}
}
}
類型 method.getParameterTypes();
