Atitit. & #160; Class & #160; & #160; Metadata reflection operation & #160; api & #160; apache & #160; & #160; tool, atitit. apache

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.