/**
* 获取操作类型说明(增加、删除、修改等)
* @param joinPoint
* @return
* @throws Exception
*/
public static String getControllerMethodDescription(JoinPoint joinPoint) throws Exception {
String targetName = joinPoint.getTarget().getClass().getName();
String methodName = joinPoint.getSignature().getName();
Object[] arguments = joinPoint.getArgs();
Class targetClass = Class.forName(targetName);
Method[] methods = targetClass.getMethods();
String description = "";
for (Method method : methods) {
if (method.getName().equals(methodName)) {
Class[] clazzs = method.getParameterTypes();
if(null != u){
description = u.option();
break;
}
}
}
}
return description;
* 获取操作类型说明(增加、删除、修改等)
* @param joinPoint
* @return
* @throws Exception
*/
public static String getControllerMethodDescription(JoinPoint joinPoint) throws Exception {
String targetName = joinPoint.getTarget().getClass().getName();
String methodName = joinPoint.getSignature().getName();
Object[] arguments = joinPoint.getArgs();
Class targetClass = Class.forName(targetName);
Method[] methods = targetClass.getMethods();
String description = "";
for (Method method : methods) {
if (method.getName().equals(methodName)) {
Class[] clazzs = method.getParameterTypes();
if (clazzs.length == arguments.length) {
//UserOperate是我自定义的切面
UserOperate u = method.getAnnotation(UserOperate.class);if(null != u){
description = u.option();
break;
}
}
}
}
return description;
}
获取方法的注解内容时,method.getAnnotation(UserOperate.class)有时候为null,需要加判断,可以暂时解决这个问题。具体为什么有时候是null的原因,我还没有搞清楚。