1. Get property values for a class
1 /* 2 cjjssetdto obj; 3 */ String filedname = "Cj" + (I+1 5 6 Cl ass<?> cl = Obj.getclass (); 7 Method me = Cl.getdeclaredmethod ("Get" +filedname); 8 9 String value = (string) me.invoke (obj);
In the cjjssetdto, known as cj1,cj2 ... The field. Because the columns are not fixed, you need to use reflection when you get the values. The values of fields such as CJ1,CJ2 are taken through a loop traversal.
2. Set the value of a property
1 /** Set Value */ 2 String filedName1 = "CJ" + (i+1); 3 Field name = Xs.getclass (). Getdeclaredfield (filedname1+ ""); 4 Name.setaccessible (true); 5 Name.set (xs,double.valueof (value)); 6 Name.setaccessible (false);
Set the values of fields such as cj1,cj2 by looping through loops.
Among them, Field is Java.lang.reflect.Field;
Method is Java.lang.reflect.Method;
Java reflection Gets the property values of a field and assigns a value to a field, among other methods