而getDeclaredFields()只能获取自己声明的各种字段,包括public,protected,private。
1、
该方法用于取得指定的实体类的实体名称。如果指定的实体类的实体标签定义了名称,则取该名称,否则取类名。
例如:有实体类SampleEntity
import javax.persistence.Entity; @Entity(name = "SpecialName") public class SampleEntity { }以SampleEntity类作为参数调用entityName方法:
1、方法中第一行,String entityName = entityClass.getSimpleName();
变量entityName的值设为类SampleEntity的短名称,即“SampleEntity”。
2、方法中第二行,Entity entity = entityClass.getAnnotation(Entity.class);
即取得SampleEntity的@Entity标签。
3、方法中第三行到第六行,if(entity.name()!=null&&!"".equals(entity.name()))
{
entityName = entity.name();
}
即@Entity标签中定义了name并且name不是空串时, 变量entityName的值设为@Entity标签中name的值,即“SpecialName”。
4、返回变量entityName,值为“SpecialName”。
如果SampleEntity的@Entity标签没有定义name
import javax.persistence.Entity; @Entity public class SampleEntity { }
方法中第三行,if(entity.name()!=null&&!"".equals(entity.name()))条件不成立,最终方法返回变量entityName,值为“SampleEntity”。
2、Method getMethod(String name, Class<?>... parameterTypes)
--返回一个 Method 对象,它反映此 Class 对象所表示的类或接口的指定公共成员方法。
parameterTypes如:String.class、int.class这些字节码才是Class类的对象
也可以此种方式:
Method method = XXX.getClass().getMethod(methodName,new Class[0]);
//getMethod第一个参数是方法名,第二个参数是该方法的参数类型,
//因为存在同方法名不同参数这种情况,所以只有同时指定方法名和参数类型才能唯一确定一个方法
如一个函数 int Test(int a, String str);
对应的getMethod方法:
1. getMethod("Test",int.class,String.class);
2. getMethod("Test",new Class[]{int.class,String.class});
然后通过invoke来调用此方法:
函数原型:Object java.lang.reflect.Method.invoke(Object receiver, Object... args)
//Method类的invoke(Object obj,Object args[])方法接收的参数必须为对象,
//如果参数为基本类型数据,必须转换为相应的包装类型的对象。invoke()方法的返回值总是对象,
//如果实际被调用的方法的返回类型是基本类型数据,那么invoke()方法会把它转换为相应的包装类型的对象,再将其返回
receiver:该方法所在类的一个对象
args: 传入的参数 如 100,“hello”
相关推荐
封装好的,https网络请求,信任所有证书模式。包含get请求模式以及post请求模式。GetMethod和PostMehtod两个类。
NULL 博文链接:https://sxk4429.iteye.com/blog/645624
使用Get方法上传数据到服务器上,GET上传的数据一般是很小的并且安全性能不高的数据,
GetMethod getMethod = new GetMethod(strURL); // 使用系统提供的默认的恢复策略 getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); ...
GetMethod getMethod = new GetMethod(url); // 设置 get 请求超时为 5 秒 getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 5000); // 设置请求重试处理,用的是默认的重试处理:请求三次 ...
at java.lang.Class.getMethod0(Unknown Source) at java.lang.Class.getMethod(Unknown Source) at sun.launcher.LauncherHelper.getMainMethod(Unknown Source) at sun.launcher.LauncherHelper....
调用空参方法 调用Object类型参数的方法 调用基本类型参数的方法 调用数组参数的方法 调用私有方法
NULL 博文链接:https://bijian1013.iteye.com/blog/2310211
基于OpenCart 1.5 的支付模块,中英文!
本人自己总结的httpClient PostMethod 上传文件完整实例 以及 使用java PostMethod 和GetMethod 发送请求实例 及乱码处理
try { Method m1 = department.getClass().getMethod("getEmployees"); Employee employees = (Employee[]) m1.invoke(department); for (Employee employee : employees) { Method m2 = employee.getClass()....
//显示某对象的某方法和某属性 show(a,"show"); } //对未知类型的对象操作 public static void show(Object obj,String method_name)throws Exception{ Class c=obj.getClass(); Field field=c.getField...
Method,invoke,getMethod等反射私有方法和私有属性
TypMis .GetMethod("PutValue").Invoke(mispos, new Object[] { "CardType", "01" }TypMis .GetMethod("PutValue").Invoke(mispos, new Object[] { "CardType", "01" }TypMis .GetMethod("PutValue").Invoke(mispos,...
java调用HTTP接口(Get请求和Post请求)
4、getAnnotation 并发线程: 三个多线程包: java.util.concurrent 包含了常用的多线程工具,是新的多线程工具的主体。 java.util.concurrent.atomic 包含了不用加锁情况下就能改变值的原子变量。 ...
该算法仅使用“名称”和参数数量调用 getMethod()。 因此,当它在 Vector 类上调用 getMethod() 方法时, remove(int index) 匹配“名称”和参数数量。 因为它是第一个匹配方法,所以它被返回。
In [634]: def getmethod(x,char='just for test'): ...: return eval('str.%s' % x)(char) ...: In [635]: getmethod('upper') Out[635]: 'JUST FOR TEST' 2、getattr In [650]: def getmethod2(x, ...
Go!... $invocation->getMethod()->isStatic() ? '::' : '->', $invocation->getMethod()->getName(), '()', ' with arguments: ', json_encode($invocation->getArguments()), " \n"; } }
通过http向服务器发出请求,进行数据交互 HttpClient client = ... client.getHttpConnectionManager().getParams().setConnectionTimeout(2000); GetMethod method = new GetMethod("http://127.0.0.1/config.xml");