Atitit. Class metadata reflection operation api apache tool, atitit. apache
Atitit. Class metadata reflection operation api apache Tool
1 BeanUtils & PropertyUtils & prop MethodUtils class usage-shorts party ConstructorUtils1
2 New instance ConstructorUtils. invokeConstructor1
3 call method MethodUtils2
4. Reference 3
1 BeanUtils & PropertyUtils & prop MethodUtils class usage-shorts party ConstructorUtils
Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://www.cnblogs.com/attilax/
2 New instance 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 (o, meth_name, null );
} Catch (Exception e ){
Return core. toJsonStrO88 (e );
}
}
Return meth;
}
3 Call method MethodUtils
1. // Use the invokeMethod method of MethodUtils to execute the method in the specified entity (without parameters)
2. System. out. println (MethodUtils. invokeMethod (entity, "haha", null ));
3.
4. // Use the invokeMethod method of MethodUtils to execute the method in the specified entity (1 parameter)
5. MethodUtils. invokeMethod (entity, "sayHelle", "Dream Fan Ying ");
6.
7. // Use the invokeMethod method of MethodUtils to execute the method in the specified entity (multiple parameters)
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 );
4 Reference
BeanUtils & PropertyUtils & MethodUtils class usage-shorts party-iteyetech website .html
Apache Commons BeanUtils package Learning (3)-ConstructorUtils. invokeConstructor, MethodUtils. invokeMethod-andevil's column-blog channel-CSDN.NET.html
Summary of atitit. java attribute Assignment Methods and BeanUtils 1.6.1. copyProperty bug-attilax column-blog channel-CSDN.NET.html
Attilax. java annotation and best practices (3) O7-attilax column-blog channel-CSDN.NET.html