1, 获取java方法中的形参定义的名称 2, 具体可以参考springmvc中对形参名称获取类
org.springframework.core.DefaultParameterNameDiscoverer dis = new org.springframework.core.DefaultParameterNameDiscoverer();
2, 测试样例如下:
package com.ysxn.change.controller;
import java.lang.reflect.Method;
public class TestField {
private String f1;
public void test(TestField name1){
}
public static void main(String[] args) {
Class clazz = TestField.class;
Method[] declaredMethods = clazz.getDeclaredMethods();
org.springframework.core.DefaultParameterNameDiscoverer dis = new org.springframework.core.DefaultParameterNameDiscoverer();
for (Method method : declaredMethods) {
String[] parameterNames = dis.getParameterNames(method);
for (String parameterName : parameterNames) {
System.out.println(parameterName);
}
}
}
}
|