Atitit. Class  元数据的反射操作 api apache  工具

Atitit. Class  元数据的反射操作 api apache  工具

 

 

1 BeanUtils & PropertyUtils & MethodUtils类使用方法 短裤党 ConstructorUtils1

2 New实例 ConstructorUtils.invokeConstructor1

3 调用方法 MethodUtils2

4 参考3

 

 

 

BeanUtils & PropertyUtils & MethodUtils类使用方法 短裤党 ConstructorUtils

作者:: 老哇的爪子 Attilax 艾龙,  EMAIL:1466519819@qq.com

转载请注明来源: http://www.cnblogs.com/attilax/

 

 

New实例 ConstructorUtils.invokeConstructor

 

private String exe(HttpServletRequest req) {

String meth = req.getParameter("method");

Handler hd = (Handler) mp.get(meth);

if (hd != null) {

try {

return (String) hd.handleReq(req);

catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

return e.getMessage();

}

}

if (hd == null) {

String classname = refx.getClassName(meth);

String meth_name = refx.getMethodName(meth);

Object o;

try {

o = ConstructorUtils.invokeConstructor(

Class.forName(classname), null);

 

MethodUtils.invokeMethod(ometh_namenull);

catch (Exception e) {

return core.toJsonStrO88(e);

}

}

return meth;

}

调用方法 MethodUtils

 

1.      //通过MethodUtils的invokeMethod方法,执行指定的entity中的方法(无参的情况)  

2.         System.out.println( MethodUtils.invokeMethod(entity, "haha"null) );  

3.           

4.         //通过MethodUtils的invokeMethod方法,执行指定的entity中的方法(1参的情况)  

5.         MethodUtils.invokeMethod(entity, "sayHelle""心梦帆影");  

6.           

7.         //通过MethodUtils的invokeMethod方法,执行指定的entity中的方法(多参的情况)  

8.         Object[] params = new Object[]{new Integer(10),new Integer(12)};  

9.         String msg = (String)MethodUtils.invokeMethod(entity, "countAges", params);  

10.         System.out.println(msg);  

 

 

参考

 

BeanUtils & PropertyUtils & MethodUtils类使用方法 短裤党 - ITeye技术网站.html

Apache Commons BeanUtils包学习(3)-ConstructorUtils.invokeConstructor,MethodUtils.invokeMethod - Anvil的专栏 博客频道 - CSDN.NET.html

atitit.java给属性赋值方法总结and BeanUtils 1.6.1 .copyPropertybug - attilax的专栏 博客频道 - CSDN.NET.html

attilax.java 注解的本质and 使用最佳实践(3)O7 - attilax的专栏 博客频道 - CSDN.NET.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值