62,614
社区成员
发帖
与我相关
我的任务
分享
public interface PersonService {
public Integer insert(Person person);
public Integer updateByPrimaryKey(Person person);
public Integer deleteByPrimaryKey(Integer id);
public Person selectByPrimaryKey(Integer id);
}
private String[] getParameterName(Class clazz,String method){
try {
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.get(clazz.getName());
CtMethod cm = cc.getDeclaredMethod(method);
MethodInfo methodInfo = cm.getMethodInfo();
CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
if (attr != null) {
String[] paramNames = new String[cm.getParameterTypes().length];
int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;
for (int i = 0; i < paramNames.length; i++)
paramNames[i] = attr.variableName(i + pos);
return paramNames;
}
} catch (NotFoundException e) {
e.printStackTrace();
}
return null;
}
getParameterName(String.class,"equalsIgnoreCase") ;
理应返回anotherString.