1、参数值
Object[] args = joinPoint.getArgs();
2、参数名称
Signature signature = joinPoint.getSignature();
if (signature instanceof MethodSignature) {
MethodSignature methodSignature = (MethodSignature) signature;
String[] properties = methodSignature.getParameterNames();
}
3、返回类型
Signature signature = joinPoint.getSignature();
if (signature instanceof MethodSignature) {
MethodSignature methodSignature = (MethodSignature) signature;
// 被切的方法
Method method = methodSignature.getMethod();
// 返回类型
Class<?> methodReturnType = method.getReturnType();
// 实例化
Object o = methodReturnType.newInstance();
}
4、全限定类名
Signature signature = joinPoint.getSignature();
signature.getDeclaringTypeName()
5、方法名
Signature signature = joinPoint.getSignature();
signature.getName()
工具类方法
/**
* 获取方法和参数内容
*
* @param className 类名 非必填
* @param mothodName 方法名 必填
* @param properties 参数名称列表
* @param agrs 参数列表
* @return
*/
public static String getMothodPropertion(String className, String mothodName, String[] properties, Object ... agrs) {
StringBuilder sb = new StringBuilder();
if(null != className) {
sb.append("类名:[").append(className).append("],");
}
sb.append("方法:[").append(mothodName).append("]");
if (null == agrs) {
return sb.toString();
}
boolean flag = null != properties;
int propertiesLength = properties.length;
Object obj;
for(int i = 0, length = agrs.length; i < length; i++) {
obj = agrs[i];
sb.append("\r\n参数索引:[").append(i).append("],");
if (flag && i < propertiesLength) {
sb.append("参数名称:[").append(properties[i]).append("],");
}
if(null == obj) {
sb.append("为null");
continue;
}
sb.append("类型:[").append(obj.getClass().getName()).append("],");
if(obj instanceof Collection) {
Collection collection = (Collection)obj;
sb.append("长度:[").append(collection.size()).append("],内容:[").append(collection);
} else if(obj instanceof Map) {
Map map = (Map)obj;
sb.append("长度:[").append(map.size()).append("],内容:[").append(map);
} else if(obj instanceof Object[]) {
Object[] objects = (Object[])obj;
sb.append("长度:[").append(objects.length).append("],内容:[").append(Arrays.asList(objects));
} else if(obj instanceof String) {
sb.append("内容:[").append(obj);
} else {
sb.append("内容:[").append(String.valueOf(obj));
}
sb.append("]");
}
return sb.toString();
}
效果如下