找到吸气剂
import java.lang.reflect.Method; import org.apache.log4j.Logger; /** 来 自 时 代 Java 公 众 号 - nowjava.com **/ public class Main{ public static Method findGetter(Class<?> entityClass, String field) { String methodName = "get" + field.substring(0, 1).toUpperCase() + field.substring(1); Method[] methods = entityClass.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method.getName().equals(methodName)) return method; }/*nowjava.com 提供*/ methodName = "is" + field.substring(0, 1).toUpperCase() + field.substring(1); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method.getName().equals(methodName)) return method; } methodName = field; for (int i = 0; i < methods.l