ArticleDirectory
Java Code
- PackageRong. propertyutils;
-
-
- ImportJava. util. Map;
-
- ImportOrg. Apache. commons. beanutils. methodutils;
-
- ImportOrg. Apache. commons. beanutils. propertyutils;
-
-
- Public ClassTestpropertyutils {
-
- Public Static VoidMain (string [] ARGs)ThrowsException {
-
-
- Entity entity =NewEntity ();
-
-
- // Obtain the value of the specified property through the getproperty method of propertyutils
- Integer id = (integer) propertyutils. getproperty (entity,"ID");
-
- String name = (string) propertyutils. getproperty (entity,"Name");
-
- System. Out. println ("Id ="+ ID +"Name ="+ Name );
-
-
- // Call the setproperty method of propertyutils to set the specified attribute of Entity
- Propertyutils. setproperty (entity,"Name","Mxengfan Ying");
-
- System. Out. println ("Name ="+ Entity. getname ());
-
-
- // Encapsulate all attributes and attribute values of entity into map using the Describe Method of propertyutils
-
- Map map = propertyutils. Describe (entity );
- System. Out. println ("Id ="+ Map. Get ("ID") +"Name ="+ Map. Get ("Name"));
-
-
- // Use the invokemethod method of methodutils to execute the method in the specified entity (without parameters)
-
- System. Out. println (methodutils. invokemethod (entity,"Haha",Null));
-
- // Use the invokemethod method of methodutils to execute the method in the specified entity (1 parameter)
-
- Methodutils. invokemethod (entity,"Sayhelle","Mxengfan Ying");
-
-
- // Use the invokemethod method of methodutils to execute the method in the specified entity (multiple parameters)
- Object [] Params =NewObject [] {NewINTEGER (10),NewINTEGER (12)};
-
- String MSG = (string) methodutils. invokemethod (entity,"Countages", Params );
-
- System. Out. println (MSG );
-
-
- }
-
- }
Package Rong. propertyutils; import Java. util. map; import Org. apache. commons. beanutils. methodutils; import Org. apache. commons. beanutils. propertyutils; public class testpropertyutils {public static void main (string [] ARGs) throws exception {entity = new entity (); // use the getproperty method of propertyutils to obtain the value of the specified property integer id = (integer) propertyutils. getproperty (entity, "ID"); string name = (string) propertyutils. getproperty (entity, "name"); system. out. println ("ID =" + ID + "name =" + name); // call the setproperty method of propertyutils to set the specified property propertyutils of the entity. setproperty (entity, "name", "Dream Fan Ying"); system. out. println ("name =" + entity. getname (); // encapsulate all attributes and attribute values of the entity into map = propertyutils through the Describe Method of propertyutils. describe (entity); system. out. println ("ID =" + map. get ("ID") + "name =" + map. get ("name"); // use the invokemethod method of methodutils to execute the method in the specified entity (if no parameter exists) system. out. println (methodutils. invokemethod (entity, "Haha", null); // use the invokemethod method of methodutils to execute methodutils in the specified entity (1 parameter. invokemethod (entity, "sayhelle", "mxengfan Ying"); // use the invokemethod method of methodutils to execute the method in the specified entity (multi-parameter condition) object [] Params = new object [] {New INTEGER (10), new INTEGER (12)}; string MSG = (string) methodutils. invokemethod (entity, "countages", Params); system. out. println (MSG );}}
id = 5 name = rongxinhua
name = xinmengfan Ying
id = 5 name = xinmengfan Ying
HA, HA
xinmengfan Ying say, hello!
my age is 22