public static void main(String[] args) throws ClassNotFoundException {
Class cl1 = Class.forName("com.zulijian.server.admin.controller.UserController");
//获取类中所有的方法
Method[] methods = cl1.getDeclaredMethods();
for (Method method : methods) {
ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
//获取方法上@ApiOperation注解的value值
String apiOperationValue = apiOperation.value();
System.out.println(apiOperationValue);
}
Method[] methodse = cl1.getMethods();
for (Method method : methods) {
String methodName = method.getName();
System.out.println("方法名称:" + methodName);
// Class<?>[] parameterTypes = method.getParameterTypes();
// for (Class<?> clas : parameterTypes) {
// String parameterName = clas.getName();
// System.out.println("参数名称:" + parameterName);
// }
}
}
public static void main(String[] args) throws ClassNotFoundException {
Map<String, String> map = new HashMap<String, String>();
Class cl1 = Class.forName("com.zulijian.server.admin.controller.UserController");
// 获取@ApiOperation注释
Method[] methods = cl1.getDeclaredMethods();
for (Method metho : methods) {
LoginLog log = new LoginLog();
String methodName = metho.getName();
System.out.println("方法名称:" + methodName);
ApiOperation apiOperation = metho.getAnnotation(ApiOperation.class);
String apiOperationValue = apiOperation.value();
log.setMethod(apiOperationValue);
System.out.println("方法名称:" + apiOperationValue);
map.put(methodName, log.getMethod());
}
System.out.println(map);
System.out.println(map.get("syncUser"));
}